Regression Analysis: Race condition risk in compensatePaymentIfNeededStep (PR #15527) #15550
Unanswered
kapil971390
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey team
I ran a regression analysis on PR #15527 — "fix(core-flows): avoid refunding captures made in separate completeCartWorkflow executions" — and wanted to share the findings with the community in case it helps with QA before the next release.
Risk Assessment: HIGH
The compensation step now performs database queries to check order status before refunding. If these queries return stale data or the order-cart link is not yet committed when compensation runs, payments could still be double-refunded or fail to refund when they should.
Escalated from MEDIUM — payment refunds are irreversible operations that directly affect customer funds.
What to Test
Race condition (core scenario): Trigger two concurrent
completeCartWorkflowexecutions with the samepayment_session_id. Force the first to fail after payment capture. Verify the second places the order successfully AND the first's compensation does NOT refund the captured payment.Legitimate failure path: Trigger
compensatePaymentIfNeededStepfor apayment_session_idwhere no order was placed (genuine cart failure). Verify refund still triggers correctly.Stale DB read: Simulate the order-cart link query returning empty/null due to replication lag. Verify the compensation does not incorrectly skip the refund.
Concurrent compensation: Call
compensatePaymentIfNeededSteptwice in rapid succession with the samepayment_session_id. Verify no double-refund is created.Null payment_session_id: Pass
nullorundefinedto the step. Verify it fails gracefully without corrupting state.Where It Can Break
cart_payment_collectionlink is absent → order-cart query returns empty → compensation can't detect the order → incorrect refund.refundPaymentAndRecreatePaymentSessionWorkflowis swallowed → no log, no refund, captured payment stranded.Edge Cases
Final Verdict
Before shipping, I'd recommend explicitly testing the race condition scenario: two concurrent
completeCartWorkflowruns on the same payment session — one fails after capture, one succeeds and places the order. The compensation from the failed run must not refund the payment tied to the successful order.Also verify that legitimate failures (inventory check fails, shipping fails) with no prior order still trigger refunds as expected.
Happy to share the full detailed report if useful
Beta Was this translation helpful? Give feedback.
All reactions