Fix the flaky webhook-lock test that was reddening the gate
try_lock_event_is_non_blocking_and_per_event failed about one run in three
under load, asserting re-acquisition immediately after `drop(held)`. Dropping a
sqlx Transaction does not run its ROLLBACK inline -- it queues it onto the
connection, to be flushed when that connection is next used or returned to the
pool -- so the advisory lock clears eventually, not by the time drop returns.
The assertion raced that flush. Failing runs took 5.2s and printed the
harness's "pool did not close in 5s; forcing"; passing runs took 0.2s.
The test now releases with an explicit rollback().await, which is the
deterministic guarantee a caller can actually rely on. 13 consecutive passes,
6 of them on the slow pool-contention path that used to fail.
Production is unaffected: the losing delivery has already shed its connection
and Stripe redelivers on its own backoff. The doc comment on try_lock_event
claimed drop "releases the lock" without qualification, which is what the test
was written against, so it now states that the release is prompt but not
synchronous and points callers needing it sooner at rollback().await.
This mattered because the test sits inside Sando's cargo_test gate, where an
intermittent red blocks promotes for no real reason.
Author: Max Johnson <me@maxj.phd> · 2026-07-21 21:28 UTC