Repository navigation
fix(rest/nodejs): commit completion as one SQLite transaction - #258
Open
FanouZeng-TT wants to merge 1 commit into
Open
FanouZeng-TT wants to merge 1 commit into
FanouZeng-TT wants to merge 1 commit into
Conversation
Complete Checkout reserved stock, saved the order and marked the checkout completed as three independent writes. A failure after the reservation answered 500 while leaving stock decremented and, for a checkout-write failure, an order the checkout could not reference. Run all three writes inside a single better-sqlite3 transaction so any failure rolls the reservation, order and status back together and the client can retry safely. The webhook stays outside the transaction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Category (Required)
ucp-schematool (resolver, linter, validator). (Requires Maintainer approval)Description
Complete Checkout is commented as an "Atomic Inventory Reservation and Completion", but the reservation, the order insert and the checkout update were three independent writes. A technical failure in the middle answered
500without rolling anything back:This change runs the reservation,
saveOrderandsaveCheckoutinside onebetter-sqlite3transaction, so any failure rolls the three tables back together and the client can retry safely. An out-of-stock line short-circuits the transaction instead of the previous hand-rolled release of already-reserved items. Webhook delivery stays outside the transaction because external I/O must not hold the SQLite write lock.Scope
Only the Node reference completion path and its data helper change. The HTTP contract, error envelopes, payment handling, webhook signing/delivery semantics, Python sample and schemas are untouched. The Python idempotency-race fix (#245) is a different failure mode (concurrent requests, one winner) and a different language/runtime; the Node referential-integrity and concurrency candidates are tracked separately and do not overlap these three files.
Tests
Fail-before (with the source changes reverted, fault injected by a SQLite trigger):
an order write failure rolls back the inventory reservation— expected stock unchanged, got99instead of100.a checkout write failure rolls back the order and the reservation— expected stock unchanged, got98instead of99.Pass-after:
npm test --prefix rest/nodejs— 173 passed, 0 failednpm run build --prefix rest/nodejsnpx prettier@4.0.0-alpha.8 --checkon the three changed filesgit diff --check