Repository navigation
fix(subscriptions): bound the WebSocket close frame and name a dropped client's reason - #3417
Open
angela-helios wants to merge 5 commits into
Open
angela-helios wants to merge 5 commits into
angela-helios wants to merge 5 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
This was referenced Dec 2, 2026
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 #2723
This branch is stacked on PR #3347 (#3069) and PR #3322 (#2816), and its diff includes both until they merge. Those two conflict with each other in
crates/rest/src/handlers/ws.rs; this branch carries the resolution, as its own merge commit.Behaviour change to review
1008with the reasonclient-too-slow. Before, the connection dropped without a close frame (1006). The server tries for 5 seconds; a client that still does not read is dropped without one, as before.HFS_SUBSCRIPTION_WS_BIND_TIMEOUT_MS(10000),HFS_SUBSCRIPTION_WS_SEND_TIMEOUT_MS(30000),HFS_SUBSCRIPTION_WS_CLIENT_QUEUE_CAPACITY(256). Zero is replaced by the default with a warning.Summary
All five items of the issue:
CLOSE_TIMEOUT(5 s), includingsingle-bind-onlyand the refusals before the bind.1008 client-too-slow. The manager marks a client it drops on a full queue, so a client whose subscription was deleted is not called too slow; that case still ends without a close frame. A client the manager released because its credential expired getscredential-expiredeven when it sees the release before its own timer.$eventsis id-only, limited toHFS_SUBSCRIPTION_EVENT_HISTORY_SIZE(100 by default, below the 256-notification queue) and in memory.work-with-subscriptionsskill (both mirrors) and the list of known variables. The send deadline still applies per frame whatever its size; an operator can raise it.crates/rest/tests/ws_client_deadlines.rs, next to the other tests of this handler rather than inwebsocket_integration, which does not reach the handler.1008 rather than 1013, to match the other reasons of this route.
Tests
crates/rest/tests/ws_client_deadlines.rs: bind timeout; stalled client that reads again; stalled client that never reads; queue overflow; deleted subscription.handlers/ws.rs: the close frame owed to a released client, next to the unit tests of fix(subscriptions): cap WebSocket connections waiting to bind #3347 and fix(subscriptions): close a bound websocket stream when its token expires #3322.helios-subscriptions: configured queue capacity, the too-slow mark, invalid capacities and zero timeouts.helios-rest: the environment wiring of the queue capacity.helios-hfs: the known-variables list matches the sources.Results:
cargo test -p helios-subscriptions --lib: 258 passed.--test websocket_integration: 9 passed.cargo test -p helios-rest --libwith thesubscriptionsfeature: 1149 passed.--test ws_client_deadlines: 5 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 two branches this one is stacked on and one other pending fix (#3111).