I’m creating a barebones websocket server the ring-jetty-adapter and my connection keeps timing out with an unclean connection close after 30.9 seconds. This happens regardless of what value I give to :max-idle-time . Is anyone familiar with this behavior and what is causing it? Again I’m using isolated minimal example code and I’m still getting this behavior.
Are you connecting directly to jetty or is there some kind of proxy, reverse or otherwise in the middle?
How do you know the connection isn't closing cleanly?
It’s straight connection to the local server
That’s how I know it was not a clean close
If the connection is exercised then it doesn’t close prematurely
Actually, in Chrome and Safari I get WebSocket connection closed cleanly in 31004 ms. Code=1001 Reason=Connection Idle Timeout so I’m guessing it’s closing cleanly?? And that the server is idle timing out and that the :max-idle-time seems to have no affect on the timeout behavior.
I think the ring websocket stuff is less widely used when not using ring-async so there might be corner cases there
I tried this in an async adapter as well and samesees
Misremembering an issue saw, it was actually the other way (websockets weren't working with async ring)
Are you sure it isn't the client timing it out?
I really doubt that, as websockets are persistent connections, and don’t require keep alive pinging etc. And this is behavior that figwheel never exhibited until I started using the latest ring-jetty-adapter
I would maybe add a listener on the server side for pings
Websockets have a built in ping/pong message type and if oneside is expecting those it might close the connection as dead if they are not happening
hmmmmm
you could also try forcing the newer ring adapter version to use the older version of jetty to see if that changes anything, might be a regression/change in jetty
Thats an idea
It seems like this is indeed the default timeout for jetty connections and I’m not seeing a simple path towards setting it especially while trying to keep to the public ring API. Ah well so I’m going to have to set up a keep alive ping on the client.
I believe this may have been an omitted option. I probably incorrectly assumed that the Jetty websocket timeout would cover it. The next version of Ring will update Jetty from 11 to 12, so we should be able to add the option then.
In the meantime, there is: https://github.com/ring-clojure/ring-websocket-middleware . This library provides a wrap-websocket-keepalive function that will periodically ping the client. It's probably a good idea to use that anyway, since it ensures the client is responsive in addition to keeping the connection open.
Thanks!!
BTW to summarize. :max-idle-time seems to have no effect
I’ll checkout the middleware for sure.
That's probably the option I assumed would cover the max idle time, but it likely means something different than my assumption.
Incidentally, you may also want to look at https://github.com/ring-clojure/ring-websocket-async and https://github.com/ring-clojure/ring-websocket-transit
Excellent!