Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disconnected TCPServer thread won't terminate
#11
(04-19-2022, 06:36 PM)kbriggs Wrote: I moved the disconnect to OnConnect like this:
...
The thread stayed alive and just kept calling OnExecute every 15 msec because I commented out the terminate:

Is there unread data left behind in AContext.Connection.IOHandler.InputBuffer? In between each call to OnExecute, the server checks the connection's Connected() method, and it should stop the thread once Connected() no longer returns True. However, Connected() will return True if there is unread data in the InputBuffer, even if the underlying socket is closed. Sometimes, when closing down a socket manually, you also need to clear the InputBuffer too, because of that reason.

Try this:

Code:
if Key = '' then // invalid websocket header
begin
  MadExcept.NameThread(GetCurrentThreadID, 'WebSocket No Key (' + IP + ')');
  LogData.Debug('WebSocket No Key (' + IP + ') ' + IntToStr(GetCurrentThreadID));
  AContext.Binding.CloseSocket;  // alternative to AContext.Connection.Disconnect
  AContext.Connection.IOHandler.InputBuffer.Clear;
  Exit;
end;

Reply


Messages In This Thread
RE: Disconnected TCPServer thread won't terminate - by rlebeau - 04-25-2022, 06:11 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)