Skip to content

state_exec: election_start_time_ read and written under one rule (CB-1) - #1185

Merged
transfix merged 2 commits into
masterfrom
fix/coordinator-election-time
Nov 13, 2026
Merged

transfix merged 2 commits into
masterfrom
fix/coordinator-election-time

Conversation

@transfix

Copy link
Copy Markdown
Owner

exec_coordinator::start_election writes the election's start time from the host, the membership callback or a bus thread. handle_heartbeat reads it on a bus thread to decide a victory by timeout. The time was a plain std::chrono::steady_clock::time_point (exec_coordinator.h:303; written at exec_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 before election_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_ElectionsAndHeartbeatsOnTwoThreads starts 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 runs state_exec_coordinator_test in the gcc legs. Locally on Windows (MSVC Release), state_exec_coordinator_test passes 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).

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).
@transfix
transfix merged commit 49ea153 into master Nov 13, 2026
33 checks passed
@transfix
transfix deleted the fix/coordinator-election-time branch November 13, 2026 22:57
transfix added a commit that referenced this pull request Nov 14, 2026
…#1177, #1167) into perf/threaded-s1b

The one conflict is the sanitizers' SAN_CXX_TESTS list in ci.yml: this branch added
stream_test, net_ws_client_test and ariadne_host_test, and #1167 added skeleton_test. The
list keeps all four.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant