Repository navigation
fix(subscriptions): apply the WebSocket client and token caps per caller - #3420
Open
angela-helios wants to merge 8 commits into
Open
angela-helios wants to merge 8 commits into
angela-helios wants to merge 8 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/3077-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
The caps of 16 bound clients and 16 unused binding tokens were shared by every caller of a subscription, so one caller could keep its owner from binding. A binding token now records who requested it, and both caps apply per issuer and subject, with a total of 256 per subscription. Callers without an identity share one allowance. Closes #3077
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 #3077
Stacked on PR #3417 (#2723, which contains #3347 and #3322): the diff of this branch includes those commits until they merge.
Behaviour change to review
429from$get-ws-binding-tokennames both limits.Summary
Both limits were shared by every caller that can request a token for a Subscription, so one caller could take every place and keep the Subscription's owner from obtaining a token or binding a client.
WsBindingTokenManager::generate_token_forandWebSocketManager::register_client_fortake the caller's key and apply the per-caller limit, then the total.register_client_foralso takes the credential deadline and replacesregister_client_untilfrom fix(subscriptions): close a bound websocket stream when its token expires #3322, so one call applies both checks.generate_tokenandregister_clientremain for callers without an identity, who share one allowance.validate_and_consumereturns aWsBinding(tenant, subscription, requester) instead of a pair.UserKey, so two principals never share one.Not covered: 16 or more principals acting together can still fill the total of 256 (reserving places for the writer needs #3021). Readers that bind still receive the notifications (#3018, #3023). There is no operator path to drop a subscription's clients (#2816).
Tests
ws_token.rsandws_manager.rs: the per-caller limit, a caller at its limit not refusing another, the total, and a client with both a caller and a deadline held to each.crates/rest/tests/ws_binding_caps_per_caller.rsover HTTP and a real WebSocket: a caller with 16 unused tokens gets429while another gets a token; a caller with 16 bound clients is closed with1008 too-many-clientswhile another binds; callers without an identity share one allowance.websocket_integration,ws_bind_credential_expiry,ws_client_deadlines,ws_unbound_connection_cap,ws_bind_message_sizeandsubscription_operation_route_type_live.Results:
cargo test -p helios-subscriptions --lib: 259 passed.--test websocket_integration: 9 passed.cargo test -p helios-rest --libwith thesubscriptionsfeature: 1149 passed.--test ws_binding_caps_per_caller: 3 passed.--test ws_client_deadlines: 5 passed.--test subscription_events: 5 passed.--test ws_bind_credential_expiry,--test ws_unbound_connection_capand--test ws_bind_message_size: 3 passed each.These ran on current
mainwith the branches this one is stacked on.