Repository navigation
fix(realtime): cap channels and queries across a connection - #14948
ArnabChatterjee20k merged 3 commits into
Conversation
Limits per subscription multiplied: 100 subscriptions x 100 channels x 100 queries let one connection hold tens of MB. - At most 200 channels and 100 queries across all subscriptions of a connection, on both the message and URL paths - Queries nested in and/or count, and a query takes at most 100 values, so one large query cannot stand in for many - Subscribing again with an id replaces its queries on all of its channels, so each subscription holds one set of queries Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
The change introduces new Reviewed commit: 981b93a |
🔵 Tier A · Mergeable after minor fixes
This change adds connection-wide realtime channel and query budgets, including counting nested queries and limiting query/value sizes. Reusing a subscription ID now replaces its query set across the subscription’s existing channels. Unit and E2E tests cover the new limits and replacement behavior.
Note Not approving while a bug finding is open: Keep console-tail filters in sync with query replacement
Fix with agent prompt### Issue 1
src/Appwrite/Messaging/Adapter/Realtime.php:184
**Keep console-tail filters in sync with query replacement**
Console-tail delivery uses `EventTailRegistry`'s separate filters, which are only updated for tail channels present in the current subscribe payload. Reusing this ID with `channels: []` (or adding a new channel) therefore leaves previously attached tail channels filtering with the old query, so they can deliver events that no longer match the subscription or suppress new matches.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 5
Reviewed |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
A value count alone did not bound how long a value could be, so one query could carry a ~50 KB string. Query strings are now limited to APP_LIMIT_ARRAY_ELEMENT_SIZE characters, the same as the REST API, checked before parsing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@hansi-codes review |
| foreach ($this->connections[$identifier]['roles'] ?? [] as $role) { | ||
| foreach ($this->connections[$identifier]['channels'] ?? [] as $channel) { | ||
| if (isset($this->subscriptions[$projectId][$role][$channel][$identifier][$subscriptionId])) { | ||
| $this->subscriptions[$projectId][$role][$channel][$identifier][$subscriptionId] = $data; |
There was a problem hiding this comment.
Keep console-tail filters in sync with query replacement
Console-tail delivery uses EventTailRegistry's separate filters, which are only updated for tail channels present in the current subscribe payload. Reusing this ID with channels: [] (or adding a new channel) therefore leaves previously attached tail channels filtering with the old query, so they can deliver events that no longer match the subscription or suppress new matches.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Messaging/Adapter/Realtime.php
Line: 184
Comment:
**Keep console-tail filters in sync with query replacement**
Console-tail delivery uses `EventTailRegistry`'s separate filters, which are only updated for tail channels present in the current subscribe payload. Reusing this ID with `channels: []` (or adding a new channel) therefore leaves previously attached tail channels filtering with the old query, so they can deliver events that no longer match the subscription or suppress new matches.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · bug · Reply if this doesn't apply.
bd837dd
into
fix-realtime-subscription-limits
What does this PR do?
#14945 limits each subscription, but the limits multiply: 100 subscriptions × 100 channels × 100 queries lets one connection hold tens of MB, and one user with 32 connections several GB. This PR adds a budget for the whole connection and bounds the size of a single query.
Constraints
APP_LIMIT_REALTIME_CHANNELS)1003, stays connected; URL:1008closeAPP_LIMIT_REALTIME_QUERIES)and/orequal('id', [...]))APP_LIMIT_ARRAY_PARAMS_SIZE)APP_LIMIT_ARRAY_ELEMENT_SIZE), the same as the REST APIUnchanged from #14945: 100 subscriptions per connection, 100 channels per subscription, 32 open connections per user per worker.
Subscribing again with an id was meant as an upsert, but older channels kept their old queries, so one subscription could hold several query sets and its queries couldn't be counted. Each subscription now has one set, which is also what in-band authentication already rebuilds it with.
Worst-case memory
The most one worker can be made to hold when every level is maxed out: 100 projects × 100 users × 32 connections. Measured on PHP 8.5 with the real adapter; each connection uses the spread of the budget that costs the most (50 subscriptions × 2 channels × 2 queries of 100 values each, every query near the 4,096-character limit). Subscriptions are stored once per role, so the 20-role column is a user in several teams.
A general shape for comparison: 30 projects × 100 users × 5 connections, users with 10 roles, each connection with 30 subscriptions of 3 distinct channels and 30 queries in total. It is within the limits, so it costs the same before and after.
The fleet-wide totals still grow with the number of connections; a cap on connections per worker and on guest connections per IP are follow-ups.
Test Plan
MessagingTest::testConstructSubscriptionsLimitsTotals,testConvertQueriesLimitsQuerySize,testCountQueriesIncludesNested,testSubscribeAgainReplacesQueriesOnEveryChannelRealtimeCustomClientQueryTestWithMessage::testSubscribeTotalsChecklist
🤖 Generated with Claude Code