I am new to WebSockets, and channels, and I was hoping someone can help me with the following:
I have followed the channels tutorial to create a chat server (sync in my case) and the functionality works perfectly except for a sudden disconnection in the WebSocket connection with no error showing at my server-side. (the error appears at my client only - i.e.chrome). "WebSocket connection to ‘…’ failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
Is this something to do with browser WebSocket connection lifetime? channels documentation doesn’t mention anything about reconnection (and I myself was not aware of such event till I faced it ) . I did though find a mention of reconnection on Jacob’s Kaplan Moss Heroku’s article on channels
any guidance on this?
Where and when in the process is this happening?
Is the official Channels Tutorial the tutorial that you’re working through? If so, at what point in the tutorial are you currently working on?
It is certainly the official channels tutorial. I have reached the point of enabling the channel layer to allow multiple clients or websockets to talk to each other.
I have managed to reproduce the problem (or at least I think I did):
the chat works, my server code doesn’t show any connection errors or disconnection.
however, the problem happens on my chrome console, when I hard refresh my window -the page the websocket connection is instatiated at - just to fetch my edits on css or js code, and this error specifically happens in incognito mode.
I might be doing something silly, or there is something I am not aware of.
thanks for your response.
Sounds like you’ve reached the end of page 2?
Thank you very much for your reply I really appreciate it.
Yes, I am at the end of part 2 of channels tutorial. everything is working great otherwise.
mind me asking, is it applicable in channels that I have to reconnect after a certain time of inactivity, even if the chat window was still open?
It’s possible, yes. Long-running sockets (websockets or otherwise) are subject to all sorts of timeout issues. Those can be mitigated to some degree by various polling mechanisms keeping some periodic activity going even if the primary purpose of the socket isn’t being used. But under any of a hundred different situations you’re likely to find connections dropping on occasion. They’re more stable than they used to be, but are still subject to transient interruptions. (The more complex your infrastructure, the more areas where things can go wrong. For instance, you might have a websocket server behind nginx which is behind an haproxy instance which is behind an F5. Any one of those can timeout a connection without either end knowing about it.)
wow, okay great! thank you for your informative answer!, I’ll try to mitigate and prepare for this.
Many thanks for your great help