-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix UTXO rpc clients dead lock on balance/unspent requests. #887
Conversation
…omicDEX-API into mm2.1-fix-api-deadlock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, it looks leaner, cleaner, and better than the previous concurrency map implementation.
I've left a few comments, but you can ignore them, cause they don't affect code execution.
Perhaps, these unwraps can be replaced by expect("description")
:D
We can have a race condition if 2 concurrent setprice calls are made with cancel_previous: true. So both orders will be created while it should create only 1 of them.
@sergeyboyko0791 Thanks for your review! I've made the changes, could you recheck, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- I've reproduced the problem on the old version (manipulations with the connection not needed on my side)
if run this script in a single thread mm2 returns answer fine, if run this script in two threads (e.g. second terminal tab) mm2 stops to response until the restart
balances_spam.sh
#!/bin/bash
while :
do
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"my_balance\",\"coin\":\"RICK\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"my_balance\",\"coin\":\"MORTY\"}"
done
- on
mm2.1-fix-api-deadlock
such spam script works fine in multiple threads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mm2 nodes with hundreds of orders running fine since 24h, previous problems are gone
600cbb3
I've done it because Slyris reported a race condition: when he called setprice with |
@cipig Could you test the latest commit, please? I've added explicit orders cancellation in case of errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works now, no more timeouts, thanks for the fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on OSX with my bot, previous order are correctly cancelled now.
Great, thanks to everyone for the reviews! |
#846
The problem was in concurrent requests handling. Electrum/Daemon could be easily spammed with a lot of balance/unspents requests when many swaps are started or many orders are placed at once. To avoid this I added the feature to send request only once so all other concurrent callers receive the same response once the request is finished. There was a race condition bug in this implementation - it could be possible that there is no active request at the moment, but the
list_unspent_in_progress
flag was true, which locked the call forever.@sergeyboyko0791
There are a couple of unwraps in
ConcurrentRequestMap::wrap_request
that should not panic, but I don't like them anyway 🙂 Maybe you will have an idea on how to get rid of them?@cipig @Milerius @tonymorony Could you please give this a test in both Electrum and Native modes? The easiest way to reproduce the issue was to make a lot of balance requests concurrently in the loop and then disconnect the network for a while.