A timed-out append is re-sent while the first still lands: duplicate events #2
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): a gateway append that times out is never re-sent, so a slow store cannot write the same event twice.
What happens
route_call/3calls the gateway worker withCALL_TIMEOUT(5000 ms) throughreckon_gater_retry:with_retry/2. A timeout comes back as{error, timeout}, andis_retriable_error/1treats it as transient (it is not on the non-retriable list), so the call is re-sent to a worker.But a
gen_server:calltimeout does not cancel the request. reckon-db's gateway worker (reckon_db_gateway_worker:stream_append_op/3) appends inline, and the firstappend_eventsstill runs and lands. The re-sent call then appends again: withANY_VERSION, or through the auto-versioned path that re-reads the version, the same events are stored twice.When it happens:
Done when
append_events,append_if_no_tag_matches) whose call times out is not re-sent blindly. It answers an error the caller can act on, or the retry is made safe (for example, idempotent by event id).Refs reckon-db-org/reckon-db#7 (where reckon-db bounds one append's own time below this timeout).
Threat model (Saturnus, before code)
Change.
route_call/3keeps today's retry for every request except the two appends,append_events(3 and 4) andappend_if_no_tag_matches.no_workers: nothing was selected.worker_down: thenoprocexit, where the worker was already dead when the call was made.timeout,node_down, a worker that died during the call, or an error the worker answered.reckon_gater_retry:with_retry/4takes the predicate that decides "retriable".with_retry/2,3keepis_retriable_error/1, so no other call changes and theretry_configrecord is untouched.Assets.
{ok, _}has its events stored.T1, a duplicate (this bug).
gen_server:calltimeout does not cancel the request. The worker appends inline, so the first append lands after gater has given up. A re-send then stores the events again (ANY_VERSION, or the auto-versioned path).nodedownafter delivery, and for a worker exit mid-append.{error, timeout}.worker_downis still retried.timeouton the allow-list; make the append path useis_retriable_error/1; drop the append match from the request classifier. Each must turn a test red.T2, a lost event.
{error, timeout}where gater used to retry, and that error means "outcome unknown". The append may still land, so the caller must not treat it as "not written".wrong_expected_versioninstead of a duplicate.append_events.{error, timeout}with ANY_VERSION reintroduces the duplicate one level up. reckon_evoq and the mcl callers are checked in the HANDOFF.T3, more errors surface.
node_downor Ra error reaches the caller.T4, an unbounded wait. Unchanged. The append path makes at most one call per proven non-delivery, and keeps the same attempt cap and backoff.
T5, an outside attacker. Nothing new is reachable. A hostile caller can already slow a store. The change only stops gater from multiplying that caller's writes.
Out of scope (named, not changed). The other write calls through
route_call(delete_stream,ack_event,save_subscription,remove_subscription,delete_snapshot_sync,scavenge*) are idempotent or answer an error on a second run. If one proves not to be, it gets its own issue.Correction to the last line of the body: reckon-db does NOT bound one append's own time below this timeout. A per-append time budget was tried in reckon-db#7 and dropped by Supervisor's ruling, because a budget safely inside 5 s turned the slow tail into refusals. An append in reckon-db retries up to 60 times, and on slow storage it can take well over 5 s. So this fix cannot rely on reckon-db answering in time.
To reproduce slow appends locally: run reckon-db's
reckon_db_concurrent_append_SUITEin the pinned CI image withpodman run --cpus 0.1. There, 20 writers x 100 appends take about 37 s and 36 of 2000 are refused asversion_conflict(reckon-db#7).Correction to my threat model above (from Neptunus): reckon-db does NOT bound one append below gater's 5 s. The per-append budget of reckon-db#7 c7921 was dropped by a Supervisor ruling.
{error, timeout}(outcome unknown) instead of being re-sent.{append_events, _, StreamId, Events}path that re-reads the version.Done, on main
582d7530(PR 3; Mercurius PASS r=1 on4180c45a, main merged once). Runs: 6834-6837 on the tip, main 6838/6839 green.