Database deadlocks during Alipay callbacks: whole-transaction retry and one delivery
A deadlocked callback transaction does not mean the customer payment failed. Establish whether the transaction rolled back, then retry the full unit under the original payment and order identities. Never replay only the final balance increment or ask the customer to pay again.
Continue by topic
Confirm collection terms and recovery responsibility
This concerns callback code on an owned or authorized merchant site. Public 稳付pay methods include WeChat Pay, Alipay and UnionPay, subject to configuration; this example focuses on Alipay. Confirm eligibility, callback routing, signing, querying and acknowledgments during onboarding. Production gateways, merchant parameters and secrets stay private. Ask the team about order limits, fees, refund charges and exception handling; database retries do not change commercial terms.
Merchant USDT settlement of CNY collections currently uses only TRON/TRC20. Confirm settlement conditions, costs and timing separately. A database commit is internal evidence, not receipt of settlement. Track verified payment, balance or entitlement delivery, and merchant settlement separately. Show paid but undelivered orders as processing with a review route, without promising a fixed repair time.
Separate rolled-back work from an unknown commit
For a merchant using PostgreSQL, SQLSTATE 40P01 identifies a detected deadlock and 40001 a serialization failure. Follow the actual database and driver documentation. Keep redacted order references, processing references, error codes and transaction boundaries, never notification secrets. End a failed transaction after a confirmed rollback error; a connection lost during COMMIT does not prove rollback.
For an unknown commit, open a fresh connection and read durable payment claims and delivery records using the original keys. Reuse a complete committed outcome; hold unresolved cases for reconciliation. Do not retry every unique-constraint error as a deadlock: it can mean an already processed notification or a conflicting owner. Inspect ownership and isolate permanent conflicts instead of looping forever.
Retry the complete decision and write unit
Authenticate under the formal contract and check merchant, order, amount, currency and paid state. An internal design is: BEGIN → lock order and account in a consistent resource order → inspect payment ownership and prior delivery → write one ledger effect and a unique delivery task → COMMIT. This is merchant pseudocode, not 稳付pay API fields. Keep transactions short and do not call remote fulfillment while holding locks.
Simulate orders A and B crediting one account. All code paths must acquire resources in the same order. After a retryable rollback, restart at BEGIN, reread current state and recompute the entire decision. Use bounded retries with jittered backoff, then a recoverable pending item. Acknowledge only when durable receipt and recoverable responsibility satisfy the actual contract; a rolled-back transaction cannot justify a fabricated success acknowledgment.
Recover exceptions and prove the result
For remote fulfillment, save a unique task in the local transaction and deduplicate its execution using the original delivery identity. A local transaction cannot prove exactly-once remote effects. Notification replays and authorized query recovery must use the same posting path. Retries must not create new payment, order or delivery identities. Upstream retries are finite, so maintain a merchant review queue.
Use simulated data in isolation to test reversed lock order, disconnect before commit, lost acknowledgment after commit, concurrent notifications and permanent amount conflicts. Prove one entitlement effect per purchase, no half-written ledger after rollback, and recovery of unknown results under the original reference. Reconcile paid, pending delivery, delivered and settlement states, including the oldest pending item and its owner. Do not create real payments or query customer transactions.
Frequently asked questions
Will a longer database timeout cure deadlocks?
No. Review cyclic lock dependencies, consistent resource order, transaction scope and full retries. A timeout change alone can hide blocking.
Can a rolled-back merchant transaction mark the payment unpaid?
No. Local rollback does not reverse verified upstream payment. Preserve that evidence and recover delivery using trusted payment information.