Fix: DO-5316 originating WebSocket channel being notified about their own variable updates #395
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.
Motivation and Context
When using the
BackendStore
persistence forVariable
s, the user who caused the update would also receive a WS message about the change. This would cause potential race conditions and state desyncs where if the variable changes multiple times while an update is being sent to the backend, the client can then get set 'back in time' after they receive a delayed notification about their own update.This is especially noticeable on slower connections and when storing objects in the variables (as Recoil might skip updates for same primitive values).
Implementation Description
Added
ws_channel
parameter to the request forPOST /api/core/store
. We then set the context varWS_CHANNEL
before invokingstore.write()
.Inside the backend store notification logic, we pass the current
WS_CHANNEL
into the websocket manager'sbroadcast
andsend_message_to_user
methods as anignore_channel
kwarg.Implemented the aforementioned
ignore_channel
kwarg to skip sending updates to a provided channel.Any new dependencies Introduced
How Has This Been Tested?
Verified in a local app that WS updates are sent to a different tab of the same user but not to themselves.
Updated client- and backend-side tests to cover the new behaviour.
PR Checklist:
Screenshots (if appropriate):