Reputation: 55
I am working on the application where I have used angular in frontend and go in backend, using websocket ( RxJs, Gorilla ). The websocket connections disconnect every 7 minutes. I didn't set anywhere 7 minutes as timeout. I did ngnix config changes as proxy read timeout as 7d, keep alive timeout as 7d. Also we use Aws ALB( load balancer). No idea why it is happening? Please help me out. Do I need to make any config changes? Because I have monitored the application that if websocket connections are alive it is working fine, only after few minutes it started reacting weird. So I have feeling it is not the issue in the code, but some configuration
Upvotes: 0
Views: 1044
Reputation: 183
In RFC, websocket is not a keep-alive connection and protocol. That means, you must design an architecture to verify and make it alive. See also RFC 6455 and PING, PONG definitions.
Once your heartbeat signal keeps the response to the endpoint on server (as I knew, this ping/pong can be guided from client too), the underlying protocol layer will identify this connection is alive, or it must be closed for complying with the spec.
Some frameworks might have wrapped a builtin keep-alive mechanism for serve it, so check their references at first.
And, Gorilla haven't handle it so you have to implement it manually. But this is a super-easy work and there're many sample codes, such as gorilla websocket chat sample: client and server, and
SetPongHandler
.
BTW, any communication errors upon websocket layer should cause the ws connect closed. In this case, a stable communication framework should be designed to have ability to manage the reconnecting event.
Upvotes: 1