Skip to content

fix(repair): 修复 InventoryService.deduct 的并发竞态条件#23

Open
deibudei wants to merge 1 commit into
demo/fault/race-conditionfrom
repair/pr-race-20260506-002410
Open

fix(repair): 修复 InventoryService.deduct 的并发竞态条件#23
deibudei wants to merge 1 commit into
demo/fault/race-conditionfrom
repair/pr-race-20260506-002410

Conversation

@deibudei
Copy link
Copy Markdown
Owner

@deibudei deibudei commented May 5, 2026

Auto Repair

Session: pr-race-20260506-002410

Plan

RepairPlan[repairTarget=修复 InventoryService.deduct 的并发竞态条件, rootCauseHypothesis=deduct 方法先读后写未加锁,多线程同时读到相同库存并通过校验后扣减,导致超卖。, suspectedFiles=[target-service/src/main/java/com/example/targetservice/service/InventoryService.java, target-service/src/main/java/com/example/targetservice/repository/InventoryRepository.java, target-service/src/test/java/com/example/targetservice/service/InventoryServiceConcurrencyTest.java], steps=[在 InventoryRepository 新增原子扣减方法 deductStock(sku, quantity),使用 ConcurrentHashMap.compute 保证读-校验-写原子性。, 重构 InventoryService.deduct 调用 repository.deductStock,移除本地非原子逻辑。, 运行 InventoryServiceConcurrencyTest 验证并发扣减不再超卖。], testCommand=mvn -pl target-service test]

Review

Patch is limited to target-service and tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant