concurrent_append_SUITE: twenty_writers_on_one_stream_keep_every_event times out intermittently (writer did not finish in 30 s) #7
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 (bug):
reckon_db_concurrent_append_SUITEtwenty_writers_on_one_stream_keep_every_eventpasses or fails on the same code, so a red CI run on reckon-db says something real again.What happens
On the forge runners the case sometimes fails with:
One of the twenty writers does not report back within the suite's fixed 30 s wait (
after 30000 -> ct:fail("writer ~p did not finish", [Pid]), test/.../reckon_db_concurrent_append_SUITE.erl:374). Everything else in the job passes: the other 299 ct cases, eunit (712), xref, lint and dialyzer.Seen on
af75fd4: push run 20, job 27020 (first attempt task 21144). Failed in the Erlang job.9d8ce2a: push run 21, task 21146. Failed on this case.af75fd4, task 21133), so this is intermittent, not deterministic.The case came from
0c794a6(5.11.13, "two concurrent appends to one stream no longer lose events"). reckon-db#2 does not touch the append path.Unknown: whether a writer is really stuck (a lost reply or a retry loop under contention) or just slow on a loaded shared runner. Telling those two apart is the first step.
Done when
Refs reckon-db-org/reckon-db#2 (ruled a flake there, not part of it).
Third occurrence: reckon-db#2 tip
9d8ce2a, pull_request run 22 (task 21149, job 27024) failed on the same case with the same{test_case_failed,"writer <0.6281.0> did not finish"}, ct 299 passed / 1 failed, everything else green. That makes it 3 failures out of the last 4 Erlang runs on this code (it passed on run 6569).Another red, from Terra: main run 6609 on
9d8ce2a, job 27104, same case and the samewriter <0.6281.0> did not finish, with 299 passed. That run uses the old fixed-30 s wait, so it carries no stack. PR 8 adds the progress-bounded wait and the stall dump that name slow versus stuck.Cause, from PR 8's diagnostics (push run 25, task 21238; PR run 24 passed all 300):
{error,{version_conflict,-2,1788}}and{error,{version_conflict,-2,510}}, having lost 60 races in a row (APPEND_ATTEMPTS). No event was lost.Proposed fix (scope ruling pending): a backoff cap that scales with the measured commit time, with a hard bound kept.
Threat model for the backoff change (before code)
Change. The pause before a retry is the same doubling as today,
min(APPEND_BACKOFF_CAP_MS, 2^(N-1)), but counted in units of the measured duration of the attempt that just lost (at least 1 ms) instead of fixed 1 ms units. That duration includes queueing behind the other writers, so the pause grows with both disk speed and contention. On a fast disk the unit is about 1 ms and behaviour is as today. Each append also gets a hard time budget: retries stop at a monotonic deadline, every pause is clipped to the time left, and running out answersversion_conflict, as the 60-attempt cap already does. The attempt cap stays.Assets. Every acknowledged event is stored exactly once at its verified version. A caller gets an answer in bounded time.
T1, a lost or overwritten event. The change touches only how long the append waits before re-reading. The version guard inside the transaction (
append_guard/3) is unchanged, so a write either lands at a verified version or aborts. There is no new write path. Proof: the suite's every-event-landed assertions, plus mutants.T2, a duplicate event. reckon-gater calls the gateway worker with a 5 s timeout (
CALL_TIMEOUT) and treats{error, timeout}as transient, so it re-sends. The worker appends inline, and the timed-out first append still lands, so the event is written twice. This already happens today for any append over 5 s, and for calls queued behind a slow one in the same worker. Longer pauses would widen it. Mitigation: the per-append budget sits well below the caller's 5 s, so one append always answers before gater gives up. The queued-calls part is not fixed here; it is the gater retrying a non-idempotent call, and it is filed separately in reckon-gater.T3, an unbounded wait. The pause scales with a measured value, so one pathologically slow attempt could ask for a huge pause. Mitigation: the deadline clips every pause, so the total is at most the budget plus one attempt.
T4, a stuck Ra makes a writer spin. A transaction that does not answer returns a timeout or error, which is not
version_changed, so it goes back to the caller at once with no retry. That path is unchanged. A Ra that answersversion_changedat once, forever, is bounded by the 60 attempts and the deadline, and every retry pauses at least the 1 ms floor.T5, an outside attacker. Nothing new. Appends are reachable only through already-authorised callers. A hostile caller hammering one stream already causes contention, and the budget stops a worker from being held longer than that.
Proof planned. The pause and the deadline are pure functions with eunit tests. Mutants: drop the deadline check, drop the clip, drop the unit scaling, drop the 1 ms floor. Each must turn a test red. The 20-writer suite must pass on the forge push run, with the duration line quoted in the HANDOFF.
Done-when 4 met: two consecutive green main lint-and-test runs after the fix landed, 6733 (
25726f2b, the #7 land) and 6802 (c75dc941, the 5.12.0 release land). No main run came between them. Closing.