I am using Phoenix with Apollo and @absinthe/socket-apollo-link to listen to GraphQL subscriptions. The users spend a lot of time on the app with tab open, without refreshing the page, often they have the app open for weeks.
Disconnects happen during that time, for various reasons. When we deploy new version is one case, but users’ devices go to sleep, they disconnect from wifi, or their network is having issues.
We have been getting reports, since about updating to Phoenix 1.6.4 on the page being “stuck”. I managed to reproduce it by just leaving the page open for 24 hours too, several WebSocket disconnection happened and, when I went to my computer the phoenixSocket.isConnected()
was false
and phoenixSocket.connectionStatus()
was connecting
.
Since then, I was able to reproduce the issue, fairly reliably by doing the following, with two hosts on my local network.
- I launch the app on Host A, on port 4000.
- From Host B, I open the SSH connection and port forwarding to Host A. So that port 4000 on Host B is forwarding TCP connection to Host B on port 4000.
- On Host B, I load the page over at localhost:4000. This goes to local forwarded port, hits Host A, renders page, connections establish properly.
- I disconnect wifi on Host B for 15 seconds or so. This is short enough so that SSH session doesn’t block, but the Phoenix socket disconnects.
- I turn on the wifi on Host B.
- I can see the page in Chrome on Host B being stuck. Connection is usually “closed”, but calling
photnixSocket.connect()
has no effect.
I can re-set the connection by first calling disconnect() and then immediately connect().
I suspect this may be an issue in Phoenix.js or somewhere in my code, but I wonder if someone else had similar issues?