(08-01-2026, 11:27 AM)hamstring Wrote: Everything is working fine except the original TCP Thread is hanging in there as a ghost thread after the websocket upgrade, that is using a new thread.
I am not familiar with staspiter Websocketserver, but is there a reason why you are moving the websocket to a new thread and not managing it on the original thread? The original thread is intended to continue running until its socket connection is closed. HTTP can receive multiple requests on a single connection, but once you upgrade a connection to websocket then it can't handle anything else until it is closed. Since you have to leave the connection open to service your websocket, you may as well just keep using the original thread for that purpose.
(08-01-2026, 11:27 AM)hamstring Wrote: I am looking for a possible way on how to terminate that thread.
Indy will handle that internally once the socket connection has been closed and control flow has returned to TIdCustomTCPServer. Do whatever you need to do inside of your event handler that processed the upgrade request while the connection is still alive.
But, if for whatever reason, you really need to transfer the socket to another thread, then you will have to release Indy's ownership over the socket (which will terminate the original thread once flow returns to TIdCustomTCPServer). You can use the TIdContext.Binding.Handle property for that. Read the property to get the socket, and then set the property to Id_INVALID_SOCKET to release ownership of the socket (setting the property will not close the socket, so you will have to close it manually when you are done using it).

