fix AssertError for newer but lower message idx#194
Open
snubba wants to merge 1 commit intobakwc:masterfrom
Open
fix AssertError for newer but lower message idx#194snubba wants to merge 1 commit intobakwc:masterfrom
snubba wants to merge 1 commit intobakwc:masterfrom
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.
line 975-978
The Race Condition
Key triggering scenario — leader reconnects after restart with stale socket data:
apply_commandto Leader B →commandsWaitingReply[N] = callbackapply_command_response(message in OS socket buffer, not yet read by A)_onIncomingMessageReceived(transport.py:368), the new connection replaces the old one:self._connections[node] = new_conn, but the old socket stays registered with the pollerappend_entrieswith a snapshot →__loadDumpFile(clearJournal=True) → __raftLastAppliedjumps past Xself.__raftLeader != nodeas False —__onLeaderChanged()is never called, socommandsWaitingReply[N]is not clearedapply_command_responsewithlog_idx=XcommandsWaitingReply→X>__raftLastApplied→ False → AssertionErrorSecondary scenario — tick ordering:
The tick order is:
__applyLogEntries()→__sendAppendEntries()→_checkCommandsToApply()→_poller.poll()If
__applyLogEntries()applies entry atidx=X(advancing__raftLastAppliedto X) in the same tick that_poller.poll()delivers anapply_command_responsewithlog_idx=X, you get X > X → False.Why it "doesn't go away"
AssertionErroris a subclass of Exception. The_autoTickThreadhas a blanket except Exception at line 539 that catches it, logs it, and continues running. The popped callback is silently dropped (never called, never put incommandsWaitingCommit). If the application retries the command under the same cluster instability, it can reproduce the same race.@bakwc Can you please confirm this fix? It is hard to reproduce reliable.