Repository navigation
fix(subscriptions): close a WebSocket client that stays behind without filling its queue - #3421
Open
angela-helios wants to merge 6 commits into
Open
angela-helios wants to merge 6 commits into
angela-helios wants to merge 6 commits into
Conversation
…ires The bind handler authorized a client once at the upgrade and then streamed to it for as long as the connection lived. It now captures the expiry of the request's bearer token and closes the stream with 1008 credential-expired at that time. The websocket manager keeps the deadline with each client and drops a client past it on the next broadcast or bind. Without authentication there is no token and no deadline. Closes #2816
/ws/subscriptions/bind upgraded every request, so a peer could hold any number of connections that never send a bind message, and the memory they used stayed in the allocator arenas after they closed. The engine now holds one slot per connection waiting to bind (HFS_SUBSCRIPTION_WS_MAX_UNBOUND_CONNECTIONS, default 256). An upgrade past the limit is refused with 503 and Retry-After. The slot is given back when the bind message arrives, the connection closes, or the bind deadline passes. Every 64 closed connections the allocator is asked to return free memory to the OS. Closes #3069
…ap' into fix/2723-wip
…expiry' into fix/2723-wip # Conflicts: # crates/rest/src/handlers/ws.rs
…d client's reason Every close frame is sent within 5 seconds or given up on. A bound client that misses the send deadline or overflows its queue is closed with 1008 client-too-slow instead of a dropped connection. The bind deadline, send deadline and client queue size are configurable through HFS_SUBSCRIPTION_WS_*, and the README says what $events can and cannot recover. Closes #2723
…t filling its queue A bound client that accepted every frame inside the send deadline and kept its queue under the cap could hold queued bundles for hours. Each notification must now be delivered within HFS_SUBSCRIPTION_WS_DELIVERY_TIMEOUT_MS (2 minutes by default) of being queued, or the client is closed with 1008 client-too-slow. Closes #3080
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3080
This branch is stacked on PR #3417 (#2723, which contains #3347 and #3322), and its diff includes those commits until they merge.
Behaviour change to review
1008 client-too-slow, however few notifications it has waiting. Before, only a full queue or one frame past the send deadline closed it.HFS_SUBSCRIPTION_WS_DELIVERY_TIMEOUT_MS(120000). Zero is replaced by the default with a warning. It also bounds the send of one frame, so raisingHFS_SUBSCRIPTION_WS_SEND_TIMEOUT_MSabove it needs both raised.Summary
A client that accepted each frame inside the send deadline, and kept its queue under the cap, could hold up to 255 queued bundles for hours.
work-with-subscriptionsskill (both mirrors) and the list of known variables have the new variable.Tests
crates/rest/tests/ws_client_deadlines.rs: a slow reader under the queue capacity is closed withclient-too-slow; a client that keeps up outlives the deadline.handlers/ws.rs: the deadline given to one send.helios-subscriptions: a queued notification keeps the time it was queued; zero and configured timeouts.Results:
cargo test -p helios-subscriptions --lib: 254 passed.--test websocket_integration: 9 passed.cargo test -p helios-rest --libwith thesubscriptionsfeature: 1150 passed.--test ws_client_deadlines: 7 passed.--test ws_bind_credential_expiry,--test ws_unbound_connection_capand--test ws_bind_message_size: 3 passed each.cargo test -p helios-hfs --bin hfs env_names: 7 passed.These ran on current
mainwith the branches this one is stacked on. #3420 (#3077) is stacked on the same branch and editsws_manager.rstoo, so the later one to merge needs its branch updated.