[BUG]钱包并发消费:同一钱包两笔并发扣款后流水余额链不连贯

作者: dadiyang创建于 2026年9月28日更新于 2026年9月28日
  • The root cause (at the source code level): PayWalletServiceImpl.reduceWalletBalance (L148) reads the wallet balance using getWallet (selectById, normal read, no row lock) before the Redis lock (L155). Inside the lock, L179-181 uses the value read outside the lock, payWallet.getBalance(), to calculate the afterBalance in the transaction as afterBalance = balance - price. When multiple threads are running in parallel, each reads the same initial balance (220) outside the lock, and calculates the afterBalance as 220-110=110 inside the lock, resulting in both transactions having the same balance of 110, instead of the expected sequential decrease (110→0).

内容来源: YunaiV/ruoyi-vue-pro