Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.8.x] Add WebSocket ping/pong support #11521

Merged
merged 5 commits into from Nov 1, 2022

Conversation

mkurz
Copy link
Member

@mkurz mkurz commented Oct 28, 2022

Finally.

Fixes #3861
Fixes #9209
Fixes #10119
Fixes akka/akka-http#4147

Needs

  • documentation
  • ... probably tests ...

With this patch one can set

play.server.websocket.periodic-keep-alive-max-idle = 10 seconds

in application.conf (or PlayKeys.devSettings for dev mode) to ping the client after the server didn't hear anything from it after 10 seconds. This is exactly the way how it works in akka-http as well. You might also want to look at the notes in the RFC about the ping and pong frames.

This was inspired by akka-http's implementation, however I did not implement a custom payload for the frames. Not sure if that's even important for someone.

Also, this is not akka-http specific, it's implemented backend agnostic, so it work with the netty backend as well.
I did lots of testing on this and it works absolutly great.

@mkurz mkurz added this to the 2.8.19 milestone Oct 28, 2022
@mkurz mkurz linked an issue Oct 28, 2022 that may be closed by this pull request
@joesan
Copy link

joesan commented Oct 29, 2022

I have added a workaround to this as mentioned here:

https://stackoverflow.com/questions/73904123/play-framework-persistent-websocket-connection

Just thought of sharing!

@mkurz
Copy link
Member Author

mkurz commented Nov 1, 2022

Added documentation:


@mkurz
Copy link
Member Author

mkurz commented Nov 1, 2022

LGTmyself, we have tests, we have docs, I thought hard about the problem 😉 Will merge after CI agrees

@ihostage
Copy link
Member

ihostage commented Nov 1, 2022

Nice work, Matthias! 👍

@mkurz mkurz merged commit c7147ed into playframework:2.8.x Nov 1, 2022
@mkurz mkurz deleted the add_ws_ping_pong_support branch November 1, 2022 12:14
@mkurz
Copy link
Member Author

mkurz commented Nov 1, 2022

@Mergifyio backport main

@mergify
Copy link
Contributor

mergify bot commented Nov 1, 2022

backport main

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sending WebSocket ping
3 participants