[SOLVED] Websocket randomly reconnects when running Mopidy through a reverse SSH tunnel

I have tried all the tricks I can find for making nginx compatible with websockets, but none of them work. I am finding this very hard to debug, but after going through nginx, ssh and Mopidy logs, it does seem like it is the clients who are dropping the connection.

I was able to debug the Mopidy websocket by adding

[loglevels]
mopidy.http.handlers = debug

to my mopidy.conf. When the connections are dropped, the Tornado websocket’s on_close is triggered. As far as I can tell, this method is only called when a client has disconnected. Furthermore, the status code I am receiving on my client side is an error with status code 1006, which signifies that the connection was closed abnormally.

Here is the nginx configuration I am using https://pastebin.com/eaxu3ryy.

I think a possible solution could be to set the websocket_ping_interval in the WebsocketHandler. If this is set in the Tornado websocket, will a (Mopidy.js) client automatically respond with a pong when it receives a ping from the server? Or do you have to manually implement this behavior? My understanding is the former.

I forked the Mopidy repo and tried to set websocket_ping_interval to 20, and set up a logging event in the websocket’s on_pong function., but I did not get any output. I might have passed in the argument in the wrong place. How would I go about setting this value?

Cheers