jumaris / indyproject

Automatically exported from code.google.com/p/indyproject
0 stars 0 forks source link

Deadlock in TIdCmdTCPClient when setting TIdCommand.Disconnect to true #226

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Setting ASender.Disconnect := True in a CommandHandler will cause a 
deadlock when TIdCommandHandler.DoCommand() calls 
AContext.Connection.Disconnect(), as TIdCmdTCPClient.Disconnect() will attempt 
to wait for the calling thread to terminate.

In procedure TIdCmdTCPClientListeningThread.Run(), before 
"FClient.IOHandler.CheckForDisconnect" add:

"if not Terminated then"

In procedure TIdCmdTCPClient.Disconnect(ANotifyPeer: Boolean), after 
"begin" add:

if Assigned(FListeningThread) and not IsCurretThread(FListeningThread) then 
begin
  FListeningThread.Terminate;
  inherited Disconnect(ANotifyPeer);
  Exit;
end;

Original issue reported on code.google.com by gambit47 on 26 Jun 2012 at 11:20