CI flake: leadership_transfer_new_leader_serves_existing_subscription times out on is_active (5 s) during the transfer #14
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Purpose (fix): the leadership-transfer case of the cluster join-subscriptions suite is deterministic, so a red on it names a real defect and never holds a release.
Case.
reckon_db_cluster_join_subscriptions_SUITE:leadership_transfer_new_leader_serves_existing_subscriptionAttempt 1. Tag v5.12.0 on
c75dc941, publish-hex run 6803, job 27753 (compile + NIFs + xref + lint + eunit + ct + proper + dialyzer, OTP 28.4.3). ct: 300 passed, 1 failed, this case:eunit was 712/712. The same case passed on main run 6802 for the same commit
c75dc941. The code is identical, so this is a timing failure. Areckon_db_leader:is_active/1call to a node did not answer within the default 5 sgen_server:calltimeout during the leadership transfer.Ruled by the dispatcher: one rerun of job 27753 under this issue. The rerun's outcome is commented below.
Done when:
is_activeon the new leader can block for 5 s or more during a transfer (a slow runner, a call into a node that is still electing, or a leader process busy in the transfer itself).Findings for whoever builds this — from Hygiea, who was reassigned off it. Nothing is pushed and no worktree of mine remains; the branch
hygiea/14-leadership-transfer-flakecarried no commits.Verdict: PRODUCT, not a test timing artefact
The gaining node's leader worker cannot answer
is_active/1at all while it activates, and activation is exactly what runs right after the transfer the case waits for.The code path,
src/reckon_db_leader.erl:handle_cast({do_activate, StoreId}, State)runssave_default_subscriptions/1(khepriexists, maybesubscribe) and thenactivate_leadership/2inline in the gen_server loop.handle_cast({activate, StoreId}, State)runsactivate_leadership/2the same way.activate_leadership/2doesget_subscriptions/1(reckon_db_subscriptions:list/1→ khepriget_many),start_emitters_for_subscriptions/2(reckon_db_emitter_pool:start_emitter/2per subscription),resume_links/1, telemetry — and only then{noreply, State#state{active = true}}.is_active/1isgen_server:call(Name, is_active)with the default 5000 ms on that same process. So for the whole of activation it queues behind the cast; the suite'speer:call(FollowerPeer, reckon_db_leader, is_active, [?STORE])is a 5 sgen_server:callto the peer, so it fails first.Why it is not test-only.
src/reckon_db_node_monitor.erl:243callsreckon_db_leader:is_active/1on every tick, same 5 s default, inside the monitor's own loop (reactivate_if_inactive/2viamaybe_reactivate_leader/2). A leader blocked in activation crashes that tick — a production symptom, not a suite one. Availability of the leader API currently depends on how long khepri takes during a transfer.The precedent is in the same file. The DCB re-index was moved off this loop for precisely this reason;
reindex_dcb/2's doc comment: "on a large DCB log it takes long enough that running it in this loop blocked is_active/1, the node monitor's call timed out every tick, and its crash restarted the gateway pool (rest_for_one)". Activation is the same class and was not moved. Also notemaybe_start_emitter_pool/3's comment inreckon_db_subscriptions.erl, which names the deadlock risk of callingis_active/1from inside the leader worker.Repro attempts (honest: no local red)
init_per_testcasewith{boot_failed,{exit_status,1}}frompeer:start, because two runs in one VM family clash on peer nodes. Not this flake; discarded.syncloop (ra is disk-bound): all passed locally. The CI box was slower than that, or the transfer timing differed.==== Running Common Test suites...at line 1127 of 1149), so the activation timing from the failing run is not recoverable from it.Fix plan
{activated, Ref}back to the loop,active = trueset only on that message,is_activeansweringfalsethroughout.active = true(carry amake_ref()per activation and accept only the live one); the worker crashing leaves the leader inactive and logged (the node monitor's next tick reactivates); two activations at once (do_activateandactivateboth arrive) start one, the second is ignored while one is in flight.is_active/1answersfalseinside a tight bound while activation is in flight, andtrueafter release. That test fails against today's inline code by construction.peer:callretryable: a 5 s call that times out is the symptom being fixed.Attempt 2 (the one rerun Mars ruled): job 27753 of tag run 6803 is green. The leadership-transfer case passed this time. 27750 (Test the release commit) and 27752 (Publish to hex.pm) ran after it and are green. reckon_db 5.12.0 is on hex.
So the case went 1 red, 1 green on the same
c75dc941. The fix stays as planned: activation leaves the leader loop (Hygiea, c8259).Closed. Landed in
acc1aa94(PR 16, reviewed by Mercurius: r1 FAIL, r2 PASS). Shipped as reckon_db 5.12.1 on hex (checksum 80f92acb775c8a2478b69b76c74d7704c5a4f177f61a494a83e94c3c6e4b31a5, tag run 6852).Done-when:
reckon_db_leaderran its whole activation (default subscriptions, khepri get_many, emitters, resume_links) inside its own gen_server loop. During a transfer, a call tois_active/1(5 s timeout) waited behind that activation.is_active/1answers while it runs. If an activate arrives during a running activation, the running one carries on and ONE rerun is marked. An answer from an activation that is no longer current sets nothing. A crashed worker still runs a rerun that was asked for. Unit cases intest/unit/reckon_db_leader_tests.erl; each new case is red on the 5.12.0 leader, and the r1 leader fails 4 asserts of the rerun case.start_emitter(mutant_no_such_store, …)instart_emitter_for_subscription,leadership_transfer_new_leader_serves_existing_subscriptiongives "Failed 1 tests. Passed 0". It is green on the shipped code.CI: PR run 6850 and push run 6849 green on
acc1aa94, main run 6851 green.Outside this issue's scope (named in the PR's "Not in this PR"): nothing deactivates the leader when leadership is lost, because
handle_no_leaderonly logs.