Note that there are some explanatory texts on larger screens.

plurals
  1. PODeadlock on tidtcpserver.active = false (Delphi2007/indy10)
    primarykey
    data
    text
    <p>I am having a problem with some code that was written by a developer that has now left our company, the code implements a tcpserver that responds to an XML based protocol. This appears to be working absolutely fine in our test environment but one or two customers are having problems with application shutdown. </p> <p>I have traced this to what appears to be a deadlock when tidtcpserver.active = false is called. I am already aware that a deadlock can be caused by one of the connection treads making a synchronised call to the main thread, whilst the main thread is waiting for the connection threads to terminate. </p> <p>I am already using a tidthreadsafestringlist to pass the data to the main thread for processing, and where I need to call a procedure from the main thread I have created a tidnotify descendant to do this. can anyone think of anything else to look for.</p> <hr> <p>I had already been checking the exception handling, </p> <p>this is what i have in the onexecute event</p> <pre><code>try // code to handle connection including tidnotify etc.... except on E:Exception do begin if (e.InheritsFrom(EIdSilentException) = False) then TXMLTraceNotify.XMLTrace('TCPServerExecute: ' + E.Message,ttProblem, FTraceProc); raise; //we must raise all exceptions for indy to handle them. end; </code></pre> <p>end;</p> <hr> <p>Here is how i'm using the TS-stringlist</p> <p>Declaration.</p> <pre><code>public TransactionStrings: TIdThreadSafeStringList; </code></pre> <p>its created in the constructor and destroyed in the destructor.</p> <p>this is how i'm adding to it in the context of the tcpserver.</p> <pre><code> TransactionStrings.Add(newTrans.AsString); </code></pre> <p>And this is how i'm reading from it in the context of the main application thread</p> <pre><code>slXMLTrans := TStringList.Create; try slTemp := FCustomXMLServer.TransactionStrings.Lock; try slXMLTrans.Assign(slTemp); slTemp.Clear; finally FCustomXMLServer.TransactionStrings.Unlock; end; if slXMLTrans.Count &gt; 0 then begin for i := 0 to Pred(slXMLTrans.Count) do TAbstractTerminal.ProcessXMLTrans(slXMLTrans[i]); slXMLTrans.Clear; end; finally slXMLTrans.Free; end; </code></pre> <p>I think this is the correct way to use it but I await your comments.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload