Spring websocket timeout settings Spring websocket timeout settings spring spring

Spring websocket timeout settings


The websocket stays opened until either the server or the client decide to close it. However, websockets are affected by two timeouts:

  • HTTP session timeout;
  • proxy connection timeouts;

If all you have between your client and your server is a websocket connection, and you don't interact over HTTP with AJAX or requesting other pages, the HTTP session expires and some servers decide to invalidate it along with the websocket (Tomcat7 had a bug that did just that). Some other servers don't do that because they see there is activity on the websocket. See here for an extended discussion: Need some resolution or clarification for how and when HttpSession last access time gets updated.

The other timeout is with proxies. They see the connection and if there is no activity on the wire for a longer period of time, they just cut it because they think it hanged. To address this, while you don't send actual application data, you need to have a heartbeat or a ping/pong of messages from time to time to let the proxy know that the connection is still OK.

Other issues might also intervene, like a buggy browser support for websocket, how your network is configured, firewall rules, etc.

For available timeout options in Spring see the websocket documentation: Configuring the WebSocket Engine.