retrysafe
← All rules

check-then-insert-race

error

A lookup-then-insert dedupe check with no atomic claim before the effect; concurrent duplicates both pass it.

Why it goes wrong

Providers can deliver the same event twice at nearly the same instant (retries racing a slow first attempt, multiple workers). Both copies read 'not processed' before either writes the record.

Safe pattern

Replace the lookup with an atomic claim: insert the event id into a table with a unique constraint (or Redis SET NX) and proceed only if the claim succeeded.

Configure

// retrysafe.config.ts
export default defineConfig({
  rules: { "check-then-insert-race": "error" }, // or "off"
});

// or, for one line (a reason is required):
// retrysafe-ignore check-then-insert-race -- <why this is safe>