Repository navigation
state_exec: election_start_time_ read and written under one rule (CB-1) - #1185
Merged
Merged
Conversation
start_election writes the election's start from the host, the membership callback or a bus thread, and handle_heartbeat reads it on a bus thread to decide a victory by timeout. The time was a plain time_point, so the two raced. It is now an atomic count of steady_clock ticks, stored before election_in_progress_ is set, so a reader that sees an election in progress reads that election's start and never an earlier one's. CB01_ElectionsAndHeartbeatsOnTwoThreads starts elections on one thread while another delivers heartbeats; the TSan legs report the race without the fix. Stage 0 found the bug (CB-1 in threaded-impl/S2.md, approved in S1-Q10 and S2-Q14).
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.
exec_coordinator::start_electionwrites the election's start time from the host, the membership callback or a bus thread.handle_heartbeatreads it on a bus thread to decide a victory by timeout. The time was a plainstd::chrono::steady_clock::time_point(exec_coordinator.h:303; written atexec_coordinator.cpp:332, read at 512), so the two raced.It is now
election_start_ticks_, an atomic count of steady_clock ticks. It is stored beforeelection_in_progress_is set, so a heartbeat that sees an election in progress reads that election's start, never an earlier one's.Test.
CoordinatorTest.CB01_ElectionsAndHeartbeatsOnTwoThreadsstarts 2000 elections on one thread while another delivers 2000 heartbeats, with an hour-long timeout, so no victory is possible. On Windows it passes either way; the race shows under TSan, which runsstate_exec_coordinator_testin the gcc legs. Locally on Windows (MSVC Release),state_exec_coordinator_testpasses 75 of 75, and CB01 passes 20 of 20.Stage 0 found this bug. It was approved as one of three small fixes in Stage 1's plan (S1-Q10) and is CB-1 in Stage 2's plan (
state-exec-perf/threaded-impl/S2.md, S2-Q14).