What happen to socket when user closes browser tab?


I need to know, what happens to the opened socket when user closes the browser tab or set hist computer to sleep ? do I have to any thing at server to avoid uncleaned resources related to opened socket? what’s the recommendation? as I am opening socket for each visitor once opening the website page.


Hi @sabri, the socket is terminated when the browser disconnects, which is what happens when the tab is closed or the computer goes to sleep. No manual cleanup is required.

Thank you @benwilson512, that’s super great :slightly_smiling_face:

I have a follow up question, If we store the websocket connection state in a registry to send messages across, we will have to clear the registry if there were alot of terminating connection to avoid some kind of overflow and slow lookup performance? how would one know that the connection state in registry is no more valid ?

If the channel process is the one calling Registry.register then all of its registered entries will be automatically cleared out when it terminates. If you’re storing the channel’s pid in the registry via some OTHER process then that’s likely not the architecture you want.