You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prevent duplicate completion of suspended sale (race condition) #4788
Sale::save_value() does not atomically verify the existing sale is still in SUSPENDED status before clearing its details and applying balance changes. Two concurrent unsuspend requests can both pass the status check, both clear the payment rows, and both apply the gift-card credit — resulting in a double credit.
This is a pre-existing race, now amplified by the return gift-card credit path introduced in #4781.
Suggested fix
Atomically transition the sale status before applying balance changes:
UPDATE sales SET sale_status = ? WHERE sale_id = ? AND sale_status = SUSPENDED
Check affectedRows(). If zero, the sale was already completed by a concurrent request — roll back and return an error.
Context
Raised by CodeRabbit review on #4781. Tracked separately to keep that PR scoped to the #4779 regression fix.
Neither clear_suspended_sale_detail($saleId) (which unconditionally deletes sales_payments, sales_items_taxes, sales_items, sales_taxes for the sale) nor the subsequent sales table update() filters on sale_status = SUSPENDED. There is no atomic UPDATE ... WHERE sale_id = ? AND sale_status = SUSPENDED with an affectedRows() check anywhere in this method, so two concurrent unsuspend requests can both pass an earlier status check, both clear the payment rows, and both apply balance changes (e.g. gift-card credit) — the race condition described in the issue is not guarded against.
No related commits addressing this were found in the current git history. This looks like it is still open for a fix.
Activity
objecttothis commentedon Oct 29, 2026
Claude Issue Checker Agent (cc @objecttothis)
Status: Still present in master.
I reviewed
Sale::save_value()inapp/Models/Sale.php(master, around lines 520–575). The update path for an existing sale is:Neither
clear_suspended_sale_detail($saleId)(which unconditionally deletessales_payments,sales_items_taxes,sales_items,sales_taxesfor the sale) nor the subsequentsalestableupdate()filters onsale_status = SUSPENDED. There is no atomicUPDATE ... WHERE sale_id = ? AND sale_status = SUSPENDEDwith anaffectedRows()check anywhere in this method, so two concurrent unsuspend requests can both pass an earlier status check, both clear the payment rows, and both apply balance changes (e.g. gift-card credit) — the race condition described in the issue is not guarded against.No related commits addressing this were found in the current git history. This looks like it is still open for a fix.
fix(sales): prevent completing a suspended sale twice