fix: send-message pending task race condition#3538
Merged
isekovanic merged 2 commits intodevelopfrom Apr 7, 2026
Merged
Conversation
Contributor
SDK Size
|
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.
🎯 Goal
This PR resolves a very long standing race condition that has evaded me for quite a while.
Whenever we queue up send message requests while we're offline, they are to be executed when we regain connection. However, the UI SDK takes care of failed messages in the sense of re-adding them in case they weren't resolved or saved in the LLC. This is done so that when a resync happens of the channel, the state is preserved and the failed messages do not disappear.
However, since our state layer is not LLC only fully, we have 2 vectors of resyncing the SDK:
channel.watch()being called)When
send-messagepending tasks are executed, the LLC takes care of upserting the state immediately so that the UI SDK can simply consume it. This is fine, except for the fact that for the UI SDK to also resolve its own state, we rely on WS events (which might be a bit late, especially for the last 1-2 messages, which is when this bug would mostly happen).So the flow would look something like this:
channel.state.messagesare updated (from the pending task execution)onSyncStatusChangecallback is invokedchannelis actually resyncedchannel.watch()is calledmessagefor which we did not receive a WS event of the successful pending task execution on time, both the failedmessageand the actual (serverside) one appear in the listTo fix this, we deem messages eligible for recovery if they:
FAILEDchannel.stateThis makes sure that the race condition never happens when the state is already up to date. If it's not, we anyway have to do it.
🛠 Implementation details
🎨 UI Changes
iOS
Android
🧪 Testing
☑️ Checklist
developbranch