Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disconnected TCPServer thread won't terminate
#10
Nope, it didn't work. I moved the disconnect to OnConnect like 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
      Exit;
    end;

The thread stayed alive and just kept calling OnExecute every 15 msec because I commented out the terminate:

Code:
class procedure WSServerEvents.OnExecute(AContext: TIdContext);
var st: string;
begin
  Sleep(10);  // prevent CPU max
  try
    if Assigned(AContext.Data) = False then  // rogue connection
    begin
      st := 'WebSocket Rogue (' + AContext.Binding.PeerIP + ')';
      MadExcept.NameThread(GetCurrentThreadID, st);
      st := st + ' ' + IntToStr(GetCurrentThreadID);
      LogData.AddError(st);
      AContext.Binding.CloseSocket;
//      Sleep(1000);
//      TIdYarnofThread(AContext.Yarn).Thread.Terminate;  // uses IdSchedulerofThread
    end else

One rogue connection flooded my log with over 100K entries before I shut it down.
Reply


Messages In This Thread
RE: Disconnected TCPServer thread won't terminate - by kbriggs - 04-19-2022, 06:36 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)