RTC: Implement front-end peer limits#76565
Conversation
Add client-side enforcement of peer limits for HTTP polling sync without PHP changes. Counts unique WordPress users from awareness data and rejects new clients when the room exceeds capacity (default: 2 users). Limits also apply per-user (default: 2 tabs). Configurability via wp.hooks.applyFilters for 'sync.maxPeersPerRoom' and 'sync.maxClientsPerUser'. Includes comprehensive unit tests covering peer limit enforcement, per-user tab limits, initial sync detection, and edge cases with null/missing awareness entries.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +178 B (0%) Total Size: 8.75 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in d4fd540. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23217768857
|
ingeniumed
left a comment
There was a problem hiding this comment.
Noting 3 issues that I have ran into:
- Retry: If another collaborator gets disconnected or leaves, and then a retry is hit by the 4th collaborator nothing happens (the error doesn't go away). I can see in the payload that an empty awareness is given back so I'm guessing because it's not processed, this bug is showing up.
- Page Refresh: Refreshing a page does show that a user has left, but it doesn't happen fast enough for the "too many editors connected" modal to not show up.
- Error Modal: This applies to all the modals we show for all errors - we don't have an effective way to prevent bypassing it. I am able to remove the overlay, make changes to the post, save it and override all the changes made by the other editors. If the other editors save after this happens, their changes will be saved as the "final save". But, in the revisions UI you can see the changes that the extra collaborator made if you go 2 changes back.
This error should not be retryable. The user is free to refresh or rejoin later. This will be fixed automatically by:
We do send a beacon to remove awareness state, but not all browsers may send it or it may hit a race condition.
Good point. Perhaps make an issue if you feel like this is worth effort. |
Noting that I've made #76612 for this, and assigned it to 7.1 for now. |
I suspect in this instance it's a race condition. I think it's fine to leave it, and acknowledge that it can happen. We can revisit this based on usage and since it's client side the fix can go into Gutenberg quickly. |
* RTC: Implement front-end peer limits for real-time collaboration Add client-side enforcement of peer limits for HTTP polling sync without PHP changes. Counts unique WordPress users from awareness data and rejects new clients when the room exceeds capacity (default: 2 users). Limits also apply per-user (default: 2 tabs). Configurability via wp.hooks.applyFilters for 'sync.maxPeersPerRoom' and 'sync.maxClientsPerUser'. Includes comprehensive unit tests covering peer limit enforcement, per-user tab limits, initial sync detection, and edge cases with null/missing awareness entries. * Enforce limit on first entity * Remove errant console statement * Clean up --------- Co-authored-by: pkevan <paulkevan@git.wordpress.org> Co-authored-by: chriszarate <czarate@git.wordpress.org> Co-authored-by: ingeniumed <ingeniumed@git.wordpress.org>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: 110226a |
What?
Adds client-side peer limit enforcement for real-time collaboration (RTC) sync without any PHP changes, recreating PR #75381 as a purely front-end feature.
Why?
PR #75381 limited concurrent RTC peers but required PHP backports. This implementation enforces the same limits purely on the client side by inspecting awareness data returned from the server. Avoids backport complexity while still protecting against server resource exhaustion.
How?
After each poll, count unique WordPress user IDs from awareness state.Consider the first loaded entity "primary" and enforce the connection limit on it. If over the limit, emit
connection-limit-exceedederror and disconnect. Defaults: 3 clients per room. Configurable viawp.hooks.applyFilters('sync.pollingProvider.maxPeersPerRoom', ...).Testing Instructions
Testing Instructions for Keyboard
After step 3, press Tab to focus "Retry" button, then press Enter to retry the connection.