Closed shavenking closed 5 years ago
@shavenking Hello. Yes you are right. To combat the race condition, an additional package bavix/laravel-wallet-vacuum
was implemented. Balance data is stored in single-threaded redis and the problem disappears.
https://github.com/bavix/laravel-wallet-vacuum/blob/master/src/Store.php#L18 https://github.com/bavix/laravel-wallet-vacuum/blob/master/src/VacuumServiceProvider.php#L28
You must also enable lock to combat race condition.
https://github.com/bavix/laravel-wallet/blob/master/config/config.php#L39 https://github.com/bavix/laravel-wallet/blob/master/config/config.php#L40
I close the issue, there are questions - create a new one.
For example, in CommonService#forceWithdraw:
After
$wallet = $walletService->getWallet($wallet);
, we should refresh the wallet balance, or we could run into an issue caused by race condition, like the following snippet:For now, the solution for me is acquiring my own lock, and refresh balance after locked.