Crashing at application end if CloseNetworkConnection() of a client was called

Just starting out? Need help? Post your questions and find answers here.
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Crashing at application end if CloseNetworkConnection() of a client was called

Post by Oso »

This has been a difficult bug to track down, but I can reproduce what's happening in PB. My network server has incoming connecting clients, responsible for receiving and processing data from the server. If I trigger a flag to shut down the server and use CloseNetworkConnection(client) to close each client's connection, all is fine and each client reports that its connection has ended. Finally, the server calls CloseNetworkServer() and that's fine too — all very graceful.

But if a client was still receiving a stream of data at the time the CloseNetworkConnection(client) was called, it later crashes the application at the point of termination.

EDIT: I have found from further testing that this happens where a thread sending network output is still running, even through the sending process stopped several seconds prior to the shutdown. It seems that if CloseNetworkConnection(client) is called and there is still a thread in operation, it 'can' crash when the application ends.