Netty: Websockets should respect play.server.http.idleTimeout
So a premium sponsor reached out to me regarding problems with Websockets.
Turns out the Netty server does not care about the play.server.http.idleTimeout config when upgrading a connection to a websocket. akka-http however works correctly (did extensive manually testing using https://github.com/vi/websocat and even wireshark to watch those frames).
The problem step-by-step:
- The netty backend sets up request handler which gets added to the netty pipeline via a
HttpStreamsServerHandler. - Our
PlayRequestHandlerreacts toIdleStateEventsto close connections if they are idle. - When upgrading a connection to a websocket, the handler of the connection (which is a
HttpStreamsServerHandlerwhich wraps ourPlayRequestHandler) removes itself from the pipeline. Problem here is when our request handler is not on the pipeline anymore, then also ouruserEventTriggeredhandler to close connections isn't there anymore as well!
To fix that I split out the userEventTriggered method into its own handler, which always stays in the pipeline.
This is working great, I did manual testing. However... actually I am trying to add a test to https://github.com/playframework/playframework/blob/main/core/play-integration-test/src/it/scala/play/it/http/websocket/WebSocketSpec.scala since hours, however I just can't get akka-http to work correctly, the connection always stays open, even when passing the serverconfig a idle timeout of 1 second and stopping a thread within a websockt for like 3 seconds. Netty correctly closes the connection. I am not sure what I do wrong in the test, maybe akka-http is configured different.... I need to find out.
Aaarghh... Turns out there is a bug in akka-http when http2 is enabled (which is for the TestSuite): https://github.com/akka/akka-http/issues/3959 I was bumping my head against the wall already why I can't get a test working correctly...
@Mergifyio backport main
backport main
✅ Backports have been created
-
#11523 [main] [2.8.x] Netty: Websockets should respect play.server.http.idleTimeout (backport #11420) by @mkurz has been created for branch
main