Beware of resource exhaustion in WebSocket server #276
nggit
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
WebSocket is a persistent, two-way communication. Which means servers tend to run out of ephemeral ports for clients faster...
Because WebSocket is designed to have no timeouts on most servers!
Let's use Uvicorn as an example (you can use Hypercorn or something else that is designed that way).
It's easy enough to find out your server is affected (run each command/step in a different terminal window):
This gives 0% chance on new requests.
Code
Mitigation
Use proper authentication for WebSocket applications,
do not allow guest mode.
Tremolo got you covered
I understand that applying timeouts to WebSocket is against user experience.
Tremolo implements a kind of sliding window technique, where timeouts will not occur as long as the client does not move out of the window,
which only happens when the server is really busy.
This provides a balance between safety and user experience.
Beta Was this translation helpful? Give feedback.
All reactions