04-19-2022, 06:36 PM
Nope, it didn't work. 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:
One rogue connection flooded my log with over 100K entries before I shut it down.
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.