{{ message }}
Repository navigation
fix(realtime): limit subscriptions per connection - #14440
Merged
HarshMN2345 merged 2 commits intoOct 15, 2026
Merged
HarshMN2345 merged 2 commits into
HarshMN2345 merged 2 commits into
Conversation
One connection could keep adding subscriptions until the realtime worker ran out of memory and dropped every other client with it. Connections now stop at 100 subscriptions and 100 channels (both configurable), a subscription's queries can be at most 4096 chars, and the subscription count is tracked as we go instead of rebuilding the whole metadata array on every message. Fixes appwrite#14430
Contributor
HarshMN2345
changed the base branch from
main
to
fix-realtime-subscription-limit
October 15, 2026 07:24
HarshMN2345
merged commit Oct 15, 2026
42b5176
into
appwrite:fix-realtime-subscription-limit
1 check passed
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.

What does this PR do?
A single realtime connection could keep piling up subscriptions until the worker hit its 512 MB limit and crashed, taking every other client on that worker down with it. This puts a ceiling on what one connection can hold.
_APP_LIMIT_REALTIME_SUBSCRIPTIONSand_APP_LIMIT_REALTIME_CHANNELS.Going over a limit rejects the whole batch before anything is applied and closes with 1008, same as the other subscribe policy violations. It applies to both the URL handshake and subscribe messages.
Test Plan
Added unit tests for the counting, resubscribe, unsubscribe and query length paths, and e2e tests for both limits on the URL and message paths plus the long query case. Unit tests, pint, phpstan and rector all pass locally. I couldn't run the e2e suite on my machine, so CI will be their first run.
I also replayed the attack from the issue against the real Subscribe handler (300 subs per frame on one shared channel). On main it reached 30k subscriptions holding 71.5 MB, and matching a single event took 100 ms. On this branch the very first frame gets rejected. Maxing out every limit at once (100 subs, 100 long channel names, ~1000 query values each) lands around 10 MB per connection.
Related PRs and Issues
Fixes #14430
Checklist