Skip to content

Commit

Permalink
#218 updating TIdCustomTCPServer.DoTerminateContext() to close the un…
Browse files Browse the repository at this point in the history
…derlying socket rather than closing the IOHandler.
  • Loading branch information
rlebeau committed Sep 11, 2021
1 parent 7e82a00 commit ef68fad
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Lib/Core/IdCustomTCPServer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,16 @@ procedure TIdCustomTCPServer.DoTerminateContext(AContext: TIdContext);
begin
// Dont call disconnect with true. Otherwise it frees the IOHandler and the thread
// is still running which often causes AVs and other.
AContext.Connection.Disconnect(False);
// TODO: use AContext.Binding.CloseSocket() instead. Just close the socket without
//AContext.Connection.Disconnect(False);

// RLebeau 9/10/2021: not calling disconnect here anymore. Just close the socket without
// closing the IOHandler itself. Doing so can cause AVs and other, such as in
// TIdSSLIOHandlerSocketOpenSSL, when Disconnect() calls IOHandler.Close() which
// frees internal objects that may still be in use...
AContext.Binding.CloseSocket;

// TODO: since we are in the mist of a server shutdown, should the socket's SO_LINGER
// option to enabled and set to 0 seconds to force an abortive (RSET) closure?
end;

procedure TIdCustomTCPServer.InitComponent;
Expand Down

0 comments on commit ef68fad

Please sign in to comment.