#16997·medusa

`revertUsage` 中缺少行锁,推广模块中没有累积限制

作者: codeCraft-Ritik创建于 2026年9月25日更新于 2026年9月29日
标签type: bugstatus: needs triaginghelp-wanted

In revertUsage (which is invoked whenever a cart completion fails, an authorization is declined, or compensation workflows execute):

  1. Zero Row Locks are Acquired: revertUsage() performs an un-isolated read-modify-write:
gemini
const newUsedValue = MathBN.sub(campaignBudgetData.used ?? 0, computedAction.amount)
campaignBudgetData.used = MathBN.lt(newUsedValue, 0) ? 0 : newUsedValue
await this.campaignBudgetService_.update(campaignBudgetsData, sharedContext)

If a cart failure or cancellation occurs concurrently with another customer placing an order with the same promo code, revertUsage reads a stale used count and overwrites the database with an outdated total. This clobbers concurrent registrations and corrupts campaign spend ledgers. 2. Missing Accumulator on Multi-Item Promotion Limits: In registerUsage(), when a promotion code applies across multiple items in a single cart, computedActions contains multiple actions for the same code. While CampaignBudgetType.USAGE guards against repeated increments using promotionCodeUsageMap, the promotion.limit check (lines 405–419) does not track code usage across iterations, re-reading the unmutated promotion.used entity on each line item.

内容来源: medusajs/medusa