Skip to content

fix: close race windows in charge creation and webhook processing - #16

Merged
lmoraesdev merged 1 commit into
mainfrom
chore/standardize-test-infrastructure
Jul 20, 2026
Merged

fix: close race windows in charge creation and webhook processing#16
lmoraesdev merged 1 commit into
mainfrom
chore/standardize-test-infrastructure

Conversation

@lmoraesdev

Copy link
Copy Markdown
Owner

Wrap charge+idempotency-key writes and webhook markAsProcessed+charge transition in a single DB transaction via a new TransactionRunner, with pessimistic row locking on the charge read during webhook processing. Previously these were separate writes: a crash between them could create a duplicate charge, and concurrent webhooks could lose one side's state transition. Concurrent idempotency-key inserts now resolve gracefully via the unique constraint instead of surfacing a 500. Also sets explicit DB pool/timeout limits instead of relying on driver defaults.

Wrap charge+idempotency-key writes and webhook markAsProcessed+charge
transition in a single DB transaction via a new TransactionRunner, with
pessimistic row locking on the charge read during webhook processing.
Previously these were separate writes: a crash between them could create
a duplicate charge, and concurrent webhooks could lose one side's state
transition. Concurrent idempotency-key inserts now resolve gracefully via
the unique constraint instead of surfacing a 500. Also sets explicit DB
pool/timeout limits instead of relying on driver defaults.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@lmoraesdev
lmoraesdev merged commit b393e8d into main Jul 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant