Closed harshita-srivastava-yral closed 2 months ago
@abeeshake-yral Can you please share the findings here?
These are the panics from the chrome console when loading the wallet page.
This is reproducible. This is happening when user doesn't have sufficient COYN balance but keeps voting. Steps to reproduct: Keep voting on the videos without waiting for result, see your wallet balance. @komal-rs @abeeshake-yral
This bug is from canister code
Can confirm the reproduction of the issue as suggested by @harshitasrivastav28 !
Could this be a concurrency issue @komal-rs ? This happens when the user keeps placing votes and moves on without waiting for the 'bet to be placed'. In other words, the 'spinner' on the frontend keeps spinning and the user moves on.
If I do this enough number of times, such that placed bet amount > my coin balance => the random number shows up.
yes very likely a concurency issue
do we go the 'mutex' route for placing bets then?
we do have 'insufficient balance' check in place here
this means that all the bets are passing the validation but the time taken between inter canister calls makes it a concurrency issue.
because of the calls to
receive_bet_from_bet_makers_canister
So we need to understand concurrency in canisters. I know it is single threaded but maybe it there is context switch when doing API calls, etc
graph LR
A[add_post_v2] -- fast operation --> B(validate_incoming_bet)
B -- slow operation (bet1) --> C(receive_bet_from_makers_canister)
B -- slow operation (bet2) --> D(receive_bet_from_makers_canister)
C --> E(token_event_balance)
D --> E
so, either we deduct the amount (as a reserve) before the receive_bet_from_makers_canister or use some form of mutex / semaphore (ongoing_bet = true).
but then, it would also need something like lock data structure which can retry itself until successful. Reasoning for this is:
To me, it seems like a spin-lock is ideal for this use case. Feel free to suggest a simpler approach
@komal-rs
Best practices from ICP regarding this issue - https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/inter-canister-calls#recommendation-1
Hi team,
Getting multiple user complaints that COYN balance in Wallet is reflecting incorrectly. Can we please urgently look into this.
Attaching screenshot for reference