Repository navigation
WebSocket sticky sessions plus Redis adapter for cross-instance fan-out #2524 - #2549
Merged
Merged
Conversation
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 & why
Fixes #2524 — WebSocket broadcasts are lossy at >1 srv instance. At N>1,
tx.emit('tutorialCompleted')on the completing instance only reaches sockets held by that same instance; clients parked on other instances silently miss the event.The fix is A+B together (either alone is insufficient — see the design doc):
@socket.io/redis-adapterbridges broadcasts across all instances, so a completion emitted on any instance reaches every subscribed client (fixes the core fan-out loss).Changes
package.json@socket.io/redis-adapter@8.3.0(exact; 8.x pairs with socket.io 4.x);cds.websocket.adapterblock (key: "socket.io");redis-websocketrequires (vcap.label: redis-cache). No"active": true— CF auto-activates viaUSER=vcap, off-CF stays in-memory so local/tests are untouched.srv/server.jsws:readylifecycle event. Handshake-scoped; does not touch application cookies..deploy/mta.yamltutorials-redis-websocketmanaged service (redis-cache/ standard), bound to bothtutorials-srvandtutorials-srv-qa. QA gets a distinct channel keysocket.io-qavia env override so it shares one Redis instance without broadcast collision.Verification
npm test— unit suite stays in-memory, adapter dormant, no regression.tutorials-srvto 2, prove a completion emitted on one instance reaches a WS client on the other, andnpm run loadtest:wsat 2 instances stays green. (Running post-merge on fresh origin/DEV.)Scope boundaries
Out of scope (explicitly not touched): wiring cache-coherence onto Redis (row #5), Redis-backed rate limiters (row #2), emit sites, WS service definitions.
🤖 Generated with Claude Code