After updating to play 2.6 I noticed that the websocket connection gets closed after 85 seconds when it is idle. In play 2.5 however the websocket connection stays open for +15 minutes when idle.
What changed in play 2.6 and is there a way to keep the websocket connection open in play 2.6 without manually keeping the connection alive on the application level?
A WebSocket times out if no read or write activity occurs and no Ping messages are received within the configured timeout period. The container enforces a 30-second timeout period as the default. If the timeout period is set to -1 , no timeout period is set for the connection.
The websocket-idle-timeout command sets the maximum idle time for client connections with the handler. This timer monitors the idle time in the data transfer process. If the specified idle time is exceeded, the connection is torn down.
It seems that for Play 2.6 akka http instead of netty is used for the backend. This means that a default timeout configuration is set for the akka http server.
The idle timeout can be increased by adding the following to the applications.conf file.
play.server.http.idleTimeout = 180s
However according to the play documentation:
Note: In dev mode, when you use the run command, your application.conf settings will not be picked up by the server. This is because in dev mode the server starts before the application classpath is available.
Thus for testing with longer idleTimeout one could run the play instance using:
sbt run -Dplay.server.http.idleTimeout=180s
For further documentation see:
https://www.playframework.com/documentation/2.6.x/SettingsAkkaHttp
http://doc.akka.io/docs/akka-http/current/java/http/server-side/websocket-support.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With