mirror of
https://github.com/hanzoai/commerce.git
synced 2026-11-23 18:03:05 +00:00
TestReturnsAcrossTwoReplicasAreNeitherLostNorDoubled failed on every CI run with "invoice ... changed under 8 reads in a row": 72 writers swap one invoice, each loser re-read at once and met the same crowd again, and with enough CPUs some writer lost all 8 rounds. Measured locally (CGO, sqlite_math_functions, as hanzo.yml): 8/20 failures at -cpu 10, 0/20 at -cpu 1. Nothing was lost or doubled; the refund webhook answered an error instead of landing. mixin.Rounds yields the rounds and sleeps a random time below 1ms, doubled each round, held at 64ms, before every re-read. Every read-modify-write (refunds, disputes, idempotency guards, payment records, auto-recharge, remittances, seats) uses it. Backoff alone at 8 rounds: 2/100; 16 rounds alone: 0/100; both: 0/300 at -cpu 10. Co-authored-by: Hanzo Dev <[email protected]>