concurrent_append_SUITE: twenty_writers_on_one_stream_keep_every_event times out intermittently (writer did not finish in 30 s) #7

Closed
opened 2026-12-02 07:12:45 +00:00 by neptunus · 5 comments
Member

Purpose (bug): reckon_db_concurrent_append_SUITE twenty_writers_on_one_stream_keep_every_event passes 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:

%%% reckon_db_concurrent_append_SUITE ==> {test_case_failed,"writer <0.6281.0> did not finish"}

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

  • main af75fd4: push run 20, job 27020 (first attempt task 21144). Failed in the Erlang job.
  • reckon-db#2 tip 9d8ce2a: push run 21, task 21146. Failed on this case.
  • The same code passed on PR 6 run 6569 (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

  • The cause is named: a stuck writer (a code bug) or a slow runner (the test's wait).
  • If it is a code bug, it is fixed with a test that fails without the fix.
  • If it is the runner, the wait is bounded by progress rather than a fixed 30 s, or the case gets a documented budget.
  • The case passes on consecutive forge runs of main.

Refs reckon-db-org/reckon-db#2 (ruled a flake there, not part of it).

Purpose (bug): `reckon_db_concurrent_append_SUITE` `twenty_writers_on_one_stream_keep_every_event` passes 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: ``` %%% reckon_db_concurrent_append_SUITE ==> {test_case_failed,"writer <0.6281.0> did not finish"} ``` 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 - main af75fd4: push run 20, job 27020 (first attempt task 21144). Failed in the Erlang job. - reckon-db#2 tip 9d8ce2a: push run 21, task 21146. Failed on this case. - The same code passed on PR 6 run 6569 (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 - The cause is named: a stuck writer (a code bug) or a slow runner (the test's wait). - If it is a code bug, it is fixed with a test that fails without the fix. - If it is the runner, the wait is bounded by progress rather than a fixed 30 s, or the case gets a documented budget. - The case passes on consecutive forge runs of main. Refs reckon-db-org/reckon-db#2 (ruled a flake there, not part of it).
Author
Member

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).

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).
Author
Member

Another red, from Terra: main run 6609 on 9d8ce2a, job 27104, same case and the same writer <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.

Another red, from Terra: main run 6609 on 9d8ce2a, job 27104, same case and the same `writer <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.
Author
Member

Cause, from PR 8's diagnostics (push run 25, task 21238; PR run 24 passed all 300):

  • The race finished with no stall but took 42223 ms for 20 writers x 100 appends. That is ~21 ms per committed append on the forge runner, against 0.85 ms locally (1.7 s): the runner is ~25x slower.
  • With the fixed 30 s wait gone, the real failure shows: 2 of 2000 appends answered {error,{version_conflict,-2,1788}} and {error,{version_conflict,-2,510}}, having lost 60 races in a row (APPEND_ATTEMPTS). No event was lost.
  • The retry pause is capped at a fixed 50 ms (APPEND_BACKOFF_CAP_MS). reckon_db.hrl's "20 writers stay clear of the cap" was measured on a fast disk. When commits take ~21 ms, a 50 ms pause cannot spread 20 writers apart, so a few hit the attempt cap. Slow storage reaches the cap at fewer writers.
    Proposed fix (scope ruling pending): a backoff cap that scales with the measured commit time, with a hard bound kept.
Cause, from PR 8's diagnostics (push run 25, task 21238; PR run 24 passed all 300): - The race finished with no stall but took 42223 ms for 20 writers x 100 appends. That is ~21 ms per committed append on the forge runner, against 0.85 ms locally (1.7 s): the runner is ~25x slower. - With the fixed 30 s wait gone, the real failure shows: 2 of 2000 appends answered `{error,{version_conflict,-2,1788}}` and `{error,{version_conflict,-2,510}}`, having lost 60 races in a row (APPEND_ATTEMPTS). No event was lost. - The retry pause is capped at a fixed 50 ms (APPEND_BACKOFF_CAP_MS). reckon_db.hrl's "20 writers stay clear of the cap" was measured on a fast disk. When commits take ~21 ms, a 50 ms pause cannot spread 20 writers apart, so a few hit the attempt cap. Slow storage reaches the cap at fewer writers. Proposed fix (scope ruling pending): a backoff cap that scales with the measured commit time, with a hard bound kept.
Author
Member

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 answers version_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 answers version_changed at 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.

## 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 answers `version_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 answers `version_changed` at 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.
Author
Member

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.

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.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
reckon-db-org/reckon-db#7
No description provided.