Skip to content
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

Wallet re-lock can happen in the middle of RPC call #3673

Closed
laanwj opened this issue Feb 14, 2014 · 2 comments
Closed

Wallet re-lock can happen in the middle of RPC call #3673

laanwj opened this issue Feb 14, 2014 · 2 comments

Comments

@laanwj
Copy link
Member

laanwj commented Feb 14, 2014

Not sure if this is expected: when the wallet unlock times out, this can be in the middle of an operation, resulting in different errors,

<***> Ik zie zo een sendfrom
<***>     [code] => -4
<***>     [message] => Signing transaction failed
<***> Die komt regelmatig voor
<***> Deze ook, ook met sendfrom
<***>     [code] => -13
<***>     [message] => Error: Please enter the wallet passphrase with walletpassphrase first.
<***> Of deze, ook met sendfrom
<***>     [code] => -1
<***>     [message] => CWallet::GenerateNewKey() : AddKey failed
<wumpus> ja die -13 zou je verwachten idd

As the cs_wallet lock is always held before calling wallet RPCs, a possible solution would be to aquire cs_wallet in LockWallet (https://github.com/bitcoin/bitcoin/blob/master/src/rpcwallet.cpp#L1545).

@laanwj laanwj added this to the 0.9.0 milestone Feb 14, 2014
@laanwj laanwj removed this from the 0.9.0 milestone Feb 24, 2014
MattFaus pushed a commit to MattFaus/bitcoin that referenced this issue Mar 21, 2014
… be unlocked

This is my idea on how to resolve bitcoin#3673. @laanwj suggested obtaining the `cs_wallet` lock inside of LockWallet(), but that will cause a deadlock if walletlock() were ever refactored to call LockWallet, which I think is a good idea.

Test Plan:
These changes pass `make`, but `make check` outputs several problems:

```
$ make check
Making check in src
Making check in .
Making check in qt
/Applications/Xcode.app/Contents/Developer/usr/bin/make  check-recursive
Making check in test
/Applications/Xcode.app/Contents/Developer/usr/bin/make  check-am
/Applications/Xcode.app/Contents/Developer/usr/bin/make  check-TESTS
../../../src/build-aux/test-driver: line 107:  1152 Abort trap: 6           "$@" > $log_file 2>&1
FAIL: test_bitcoin-qt
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am
make[9]: Nothing to be done for `all-am'.
============================================================================
Testsuite summary for Bitcoin Core 0.9.99
============================================================================
============================================================================
See src/qt/test/test-suite.log
Please report to info@bitcoin.org
============================================================================
make[7]: *** [test-suite.log] Error 1
make[6]: *** [check-TESTS] Error 2
make[5]: *** [check-am] Error 2
make[4]: *** [check] Error 2
make[3]: *** [check-recursive] Error 1
make[2]: *** [check] Error 2
make[1]: *** [check-recursive] Error 1
make: *** [check-recursive] Error 1
```
@MattFaus
Copy link

I took a quick look at this and figured that'd it be easier to add LOCK(cs_nWalletUnlockTime); before all of the EnsureWalletIsUnlocked(); calls. I tried putting this statement inside EnsureWalletIsUnlocked();, but that would complicate the API considerably since the caller would have to receive the lock object and then make sure to unlock it appropriately afterwards.

I also refactored walletlock to simply call LockWallet() since this looked like duplicate code to me (well, two lines are swapped in order, but that shouldn't matter).

The changes are here, but I have not been able to get make check to work, so I'm still looking into that.

https://github.com/MattFaus/bitcoin/commits/wallet_lock2

@laanwj
Copy link
Member Author

laanwj commented Sep 29, 2016

I'm not convinced that this is a problem. Besides causing RPC to spit out different error messages, it doesn't seem to ever cause real problems such as crashes. Trying to solve it is probably more risky than leaving it as-is.

@laanwj laanwj closed this as completed Sep 29, 2016
sidhujag pushed a commit to syscoin/syscoin that referenced this issue Aug 30, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants