-
Notifications
You must be signed in to change notification settings - Fork 37.7k
test: Fix inconsistent lock order in wallet_tests/CreateWallet #19982
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
Conversation
26fa3f6
to
5dc811f
Compare
186221d
to
283ddf1
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
@hebasto I'm not following, how is it revealed? |
|
Thanks @hebasto, I tried |
|
283ddf1
to
d89c332
Compare
Updated 283ddf1 -> d89c332 (pr19982.03 -> pr19982.04, diff):
|
Oh I did't have |
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.
Code Review ACK d89c332, feel free to take comments, thanks for fixing this.
AFAICT this deadlock wasn't catch by CI at #16426 merge because LEAVE_CRITICAL didn't call neither potential_deadlock_detected
or CheckLastCritical
. Otherwise if a new lock would have been taken in the rest of CreateWalletFromFile
it should have been detected.
So this PR does improve deadlock detection by flagging any lock order inconsistency even if it didn't materialize in an effective one as this case sounds to suggest ?
LEAVE_CRITICAL_SECTION(wallet->wallet()->cs_wallet); | ||
SyncWithValidationInterfaceQueue(); | ||
ENTER_CRITICAL_SECTION(wallet->wallet()->cs_wallet); | ||
ENTER_CRITICAL_SECTION(cs_wallets); |
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.
Okay I looked on, before this commit, behavior is :
TestLoadWallet()
insrc/wallet/test/wallet_tests.cpp
L794.- Calling down
CWallet::Create()
which takes thecs_wallet
lock insrc/wallet/wallet.cpp
L4007 thencs_wallets
lock insrc/wallet/wallet.cpp
L4089 - Calling down this handler, which attempt to leave the former first triggering a lock order inconsistency
For tracking the faultive commit is 6a72f26.
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.
Code review ACK d89c332. Impressive work by hebasto not only debugging and fixing the buggy wallet test, but also improving deadlock detection, and improving deadlock detection output, and writing new deadlock detection tests!
@hebasto if you feel like adding more information to #19049, I'd be curious to know more you debugged this, since I gave up there struggling to figure out which locks were involved
Note to anyone else interested in reviewing this that the change is simpler than it probably looks. The actual bugfix in the third commit is very straightforward and just two lines. The first two commits are just improvements to error handling and debug output in lock order code, ignoring a big whitespace diff in the first commit. |
d89c332
to
e2dc75f
Compare
Rebased d89c332 -> e2dc75f (pr19982.04 -> pr19982.05) due to the conflict with #20285. |
d15646b
to
f2933e7
Compare
Rebased d15646b -> f2933e7 (pr19982.06 -> pr19982.07) due to the conflict with #19337. |
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.
Code review ACK f2933e7. Since last review just rebase updating test name and tweaking comments
Notes that might be helpful to other reviewers: #19982 (comment). The actual fix is very simple and contained in the third commit. The other two commits are error checking improvements. |
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.
ACK f2933e7
lock m1
lock m2
unlock m1
unlock m2
the above was allowed before this PR and is forbidden after the PR. Such code cannot cause deadlock or any other issue and is legit. However it looks strange, may be a signal of a problem elsewhere and better be avoided. In our code in particular it would also brick the debugging mechanisms because LeaveCritical()
from unlock m1
would remove the wrong lock from the lock stack (m2
).
I think it is ok to enforce "locks should be released in reverse order in which they were acquired"
f2933e7
to
608e14a
Compare
Updated f2933e7 -> 608e14a (pr19982.07 -> pr19982.08, diff):
|
Concept ACK Nice work! |
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.
ACK 608e14a |
This commit adds actual lock stack logging if check fails.
This change reveals a bug in the wallet_tests/CreateWalletFromFile test, that will be fixed in the following commit.
608e14a
to
e1e68b6
Compare
Rebased 608e14a -> e1e68b6 (pr19982.08 -> pr19982.09) due to the conflict with #19425. |
review ACK e1e68b6 💂 Show signature and timestampSignature:
Timestamp of file with hash |
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.
Code review ACK e1e68b6. Just trivial rebase and suggested switch to BOOST_CHECK_EXCEPTION since last review
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.
ACK e1e68b6
…s/CreateWallet e1e68b6 test: Fix inconsistent lock order in wallet_tests/CreateWallet (Hennadii Stepanov) cb23fe0 [skip ci] sync: Check precondition in LEAVE_CRITICAL_SECTION() macro (Hennadii Stepanov) c5e3e74 sync: Improve CheckLastCritical() (Hennadii Stepanov) Pull request description: This PR: - fixes bitcoin#19049 that was caused by bitcoin#16426 - removes `wallet_tests::CreateWallet` suppression from the `test/sanitizer_suppressions/tsan` The example of the improved `CheckLastCritical()`/`LEAVE_CRITICAL_SECTION()` log (could be got when compiled without the last commit): ``` 2020-09-20T08:34:28.429485Z [test] INCONSISTENT LOCK ORDER DETECTED 2020-09-20T08:34:28.429493Z [test] Current lock order (least recent first) is: 2020-09-20T08:34:28.429501Z [test] 'walletInstance->cs_wallet' in wallet/wallet.cpp:4007 (in thread 'test') 2020-09-20T08:34:28.429508Z [test] 'cs_wallets' in wallet/wallet.cpp:4089 (in thread 'test') ``` Currently, there are other "naked" `LEAVE_CRITICAL_SECTION()` in the code base: https://github.com/bitcoin/bitcoin/blob/b99a1633b270e0e89479b2bb2ae19a8a8dc0fa05/src/rpc/mining.cpp#L698 https://github.com/bitcoin/bitcoin/blob/b99a1633b270e0e89479b2bb2ae19a8a8dc0fa05/src/checkqueue.h#L208 ACKs for top commit: MarcoFalke: review ACK e1e68b6 💂 ryanofsky: Code review ACK e1e68b6. Just trivial rebase and suggested switch to BOOST_CHECK_EXCEPTION since last review vasild: ACK e1e68b6 Tree-SHA512: a627680eac3af4b4c02772473d68322ce8d3811bf6b035d3485ccc97d35755bef933cffabd3f20b126f89e3301eccecec3f769df34415fb7c426c967b6ce36e6
This PR:
wallet_tests::CreateWallet
suppression from thetest/sanitizer_suppressions/tsan
The example of the improved
CheckLastCritical()
/LEAVE_CRITICAL_SECTION()
log (could be got when compiled without the last commit):Currently, there are other "naked"
LEAVE_CRITICAL_SECTION()
in the code base:bitcoin/src/rpc/mining.cpp
Line 698 in b99a163
bitcoin/src/checkqueue.h
Line 208 in b99a163