Repository navigation
fix: prevent iterator invalidation in handle_append_entries_resp during peer leave timeout - #675
Open
hardikkaurani wants to merge 4 commits into
Conversation
…sponse Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…n test suite Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Author
|
Hi @greensky00, I opened this pull request to resolve the iterator invalidation issue reported in #653 within Summary of changes:
The change is structured across 4 atomic signed-off commits. Whenever convenient, please approve the workflow run and let me know if any adjustments are needed. Thank you! |
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.
Summary
This PR fixes a critical iterator invalidation and potential use-after-free defect in
raft_server::handle_append_entries_respwhen handling append entries responses during server step-down/removal timeout (fixes #653).Problem Description
In
handle_append_entries_resp,peers_.find(resp.get_src())was executed prior tocheck_srv_to_leave_timeout():peer_itor it = peers_.find(resp.get_src()); ... check_srv_to_leave_timeout(); ... ptr<peer> p = it->second;When a leaving node (
srv_to_leave_) exceeds its timeout window during catch-up:check_srv_to_leave_timeout()triggersremove_peer_from_peers(srv_to_leave_).peers_, which immediately invalidates iteratoritif the response being handled belongs to the leaving peer.it->secondsubsequently results in dereferencing an invalidated iterator, causing segmentation faults or undefined behavior in production environments.In comparison, other handlers such as
handle_hb_timeout(src/handle_timeout.cxx) andhandle_join_leave(src/handle_join_leave.cxx) consistently invokecheck_srv_to_leave_timeout()before performing peer lookups.Key Changes
check_srv_to_leave_timeout()to the start ofhandle_append_entries_resp()beforepeers_.find(resp.get_src()). If the leaving peer timed out and was removed,peers_.find()safely returnspeers_.end(), logging and returning cleanly without crashes.ptr<peer> p = it->second;immediately upon confirmingit != peers_.end(), preventing any subsequent dangling iterator accesses.remove_srv_timeout_append_entries_resp_testintests/unit/raft_server_test.cxxand registered it in the test suite to verify late response handling for removed/timed-out servers.