-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core, api-client): Add abort controller to notifications api call (WPB-11013) #6577
Merged
Conversation
This file contains 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
przemvs
reviewed
Oct 10, 2024
przemvs
reviewed
Oct 10, 2024
przemvs
reviewed
Oct 10, 2024
przemvs
reviewed
Oct 10, 2024
przemvs
reviewed
Oct 10, 2024
Co-authored-by: Przemysław Jóźwik <[email protected]>
Co-authored-by: Przemysław Jóźwik <[email protected]>
Co-authored-by: Przemysław Jóźwik <[email protected]>
Co-authored-by: Przemysław Jóźwik <[email protected]>
Co-authored-by: Przemysław Jóźwik <[email protected]>
thisisamir98
force-pushed
the
WPB-11013
branch
from
October 11, 2024 11:08
b38e3e7
to
4cbbbf1
Compare
PR is blocked by jakearchibald/idb#327 |
thisisamir98
changed the title
fix: Add abort controller to notifications api call (WPB-11013)
fix(core, api-client): Add abort controller to notifications api call (WPB-11013)
Oct 14, 2024
- @wireapp/[email protected] - [email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected]
- @wireapp/[email protected] - [email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected] - @wireapp/[email protected]
Quality Gate passedIssues Measures |
For now we will continue with skipLibCheck: true because jakearchibald/idb#327 is not resolved yet |
przemvs
approved these changes
Oct 16, 2024
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.
Fix for Missing Messages Due to Race Condition in WebSocket/API Call Handling
Problem:
A message sent by a user was visible Android or IOS clients, but not in the web app.
We handle WebSocket connections using
reconnecting-websocket
and API calls usingaxios
andaxios-retry
. The process involves connecting to a WebSocket, locking it, fetching new messages from the/notifications
endpoint using the last known notification ID, decrypting the messages, inserting them into IndexedDB, and finally unlocking the WebSocket to allow queued messages to be processed.Identified Issue:
The root cause of the bug seems to be a race condition involving the
/notifications
API call. While anAbortController
was in place to check if the WebSocket connection dropped, we never canceled the ongoing request to/notifications
. This led to a situation where multiple API requests would fire if the network went offline and then came back online, as shown in the second attached screenshot. These multiple requests resulted in multiple sets of messages being processed simultaneously, causing inconsistencies.Fix:
By implementing the abort functionality on the API call, we now ensure that the
/notifications
request is properly canceled when the WebSocket disconnects. This should prevent multiple API responses from arriving at different times and help resolve the race condition that was likely causing the issue.Race Condition Explanation:
The issue arises when the WebSocket disconnects and reconnects, leading to multiple API calls being initiated to
/notifications
. If the WebSocket disconnects and reconnects multiple times, each reconnection initiates a new API call to fetch notifications since the last known notification ID. The problem occurs when these multiple API requests resolve at different times but carry overlapping or identical sets of messages (e.g., message IDs 0 to 500).These overlapping messages are then decrypted and processed in separate loops, which can lead to duplicate processing, especially if two responses arrive at different times, leading to the same messages being processed twice.
Scenario:
/notifications
is made to fetch new messages (IDs 0 to 500)./notifications
continues and is not canceled./notifications
for the same range (IDs 0 to 500).Visualization of the Race Condition: