(04-18-2022, 05:48 PM)kbriggs Wrote: I originally performed the disconnects in OnConnect but I saw a post from you in StackOverFlow telling someone else to do it in OnExecute. Perhaps I misunderstood the context.
That person was wanting to disconnect clients from other threads outside of the server, not from within the server threads that own each client. OnConnect, OnDisconnect, and OnExecute are all fired in the context of the same thread.
(04-18-2022, 05:48 PM)kbriggs Wrote:Quote:Do you have thread pooling enabled on your server?
I don't know what that is so probably not unless it's on by default.
Pooling is not enabled by default. You would have to manually assign a TIdSchedulerOfThreadPool component to the server in order to use pooling. What it does is holds finished threads in memory so they can be re-used for new connections later.
(04-18-2022, 05:48 PM)kbriggs Wrote:Quote:What do AdminSessionDisconnect() and PlayerSessionDisconnect() look like?
I've not had any issues with normal connections terminating. None of those leave zombie threads behind. But here are those OnDisconnect events:
And, what do AdminSessionList, AdminSessionUpdate, PlayerSessionList, SessionUpdate, and LogData look like? You are accessing a lot of shared data across thread boundaries, so I hope you are adequately and safely synchronizing access to your shared data.
(04-18-2022, 05:48 PM)kbriggs Wrote:Code:if Key = '' then Exit; // invalid websocket header, disconnect in OnExecute
if not(Admin) and not(gvar.Running) then Exit; // offline for players, disconnect in OnExecute
That would be an ideal spot to disconnect, eg:
Code:
if (Key = '') or // invalid websocket header
((not Admin) and (not gvar.Running)) then // offline for players
begin
AContext.Connection.Disconnect;
Exit;
end;
(04-18-2022, 05:48 PM)kbriggs Wrote:Code:if sysSameOriginPolicy.bValue and (Host <> Origin) then
begin
SendCloseFrame(AContext, 4000);
Sleep(1000); // enough time for writes to go out
Exit; // disconnect in OnExecute
end;
Likewise:
Code:
if sysSameOriginPolicy.bValue and (Host <> Origin) then
begin
SendCloseFrame(AContext, 4000);
AContext.Connection.Disconnect;
Exit;
end;