Make vpwallets usage thread safe #13028
pull promag wants to merge 1 commits into bitcoin:master from promag:2018-04-cs_wallets changing 1 files +7 −1-
promag commented at 1:52 pm on April 19, 2018: member
-
in src/wallet/wallet.cpp:37 in ae632bc2f3 outdated
34@@ -35,9 +35,11 @@ 35 #include <boost/algorithm/string/replace.hpp> 36 37 static std::vector<CWallet*> vpwallets;
MarcoFalke commented at 2:50 pm on April 19, 2018:Does it compile if you add aGUARDED_BY
here?
practicalswift commented at 2:57 pm on April 19, 2018:Good point @MarcoFalke!
Please add
GUARDED_BY(cs_wallets)
and verify by building with--enable-werror
usingclang
.
promag commented at 3:25 pm on April 19, 2018:Done.promag force-pushed on Apr 19, 2018jnewbery commented at 9:16 pm on April 19, 2018: memberConcept ACK.
Note that this will allow dynamically loading wallets, but more is required before we add dynamic unloading of wallets (this doesn’t prevent one thread from removing a wallet while another thread still has a pointer to that wallet).
promag commented at 1:22 am on April 20, 2018: memberthis doesn’t prevent one thread from removing a wallet while another thread still has a pointer to that wallet @jnewbery true, that’s one of the reasons to switch to shared pointers. A wallet can be unregistered and only (enqueued-to-)(unloaded+released) when reference count is zero.
fanquake added the label Wallet on Apr 20, 2018promag force-pushed on Apr 23, 2018in src/wallet/wallet.cpp:68 in c6f5b4fd0d outdated
63 return !vpwallets.empty(); 64 } 65 66 std::vector<CWallet*> GetWallets() 67 { 68+ LOCK(cs_wallets);
jonasschnelli commented at 12:10 pm on April 23, 2018:IMO the GetWallet call with returning a vector of raw pointers is dangerous. This is why I used the callable/lamda approach in #12587 (see https://github.com/bitcoin/bitcoin/pull/12587/files#diff-74d273024bfb20e7f09b87a23cd26f4dR41).
A concurrency mess-up with retrieving the pointers under the cs_wallet lock (copy of the vector), then continue outside of the
cs_wallet
lock may happen in the future.
jonasschnelli commented at 12:12 pm on April 23, 2018:This problem obviously also is also true forGetWallet()
and - for unloading - moving to a shared pointer and weak-unloading at a later stage is probably unavoidable.
jnewbery commented at 4:50 pm on April 23, 2018:Right now there’s no way to free wallets. Obviously we’ll need to change this when we add an
unloadwallet
RPC, but for now this approach is sufficient to allow us to add aloadwallet
andcreatewallet
RPC.Would it be sufficient to add a comment to these functions warning of the danger if we add a way to free wallets?
jonasschnelli commented at 6:04 pm on April 23, 2018:Maybe a comment… I think its also okay to just be aware of this and fix it once we have a way to remove pointers from the array.
promag commented at 6:09 pm on April 23, 2018:I’m working on that with shared pointers. I can include this commit there, but IMO this is not worse than master so can go in to at least protect concurrency for loadwallet.wallet: Make vpwallets usage thread safe e2f58f421bpromag force-pushed on Apr 24, 2018jonasschnelli commented at 9:29 am on April 26, 2018: contributorutACK e2f58f421b1a6e360bbf7efdfbba398918ce19d3conscott commented at 10:35 am on April 28, 2018: contributorTested ACK e2f58f421b1a6e360bbf7efdfbba398918ce19d3laanwj merged this on Apr 30, 2018laanwj closed this on Apr 30, 2018
laanwj referenced this in commit 783bb6455e on Apr 30, 2018promag deleted the branch on Apr 30, 2018PastaPastaPasta referenced this in commit a3386a3fda on Apr 14, 2020PastaPastaPasta referenced this in commit 10182d0444 on Apr 14, 2020PastaPastaPasta referenced this in commit e4b122fbf7 on Apr 14, 2020PastaPastaPasta referenced this in commit 5d02fa540e on Apr 15, 2020PastaPastaPasta referenced this in commit bdf4fb3cfc on Apr 15, 2020PastaPastaPasta referenced this in commit 93248e49d4 on Apr 15, 2020PastaPastaPasta referenced this in commit c0c46932d5 on Apr 15, 2020PastaPastaPasta referenced this in commit af06fb5cd6 on Apr 16, 2020PastaPastaPasta referenced this in commit 1217f87cb7 on Apr 16, 2020PastaPastaPasta referenced this in commit 2d8a3d1295 on Apr 26, 2020PastaPastaPasta referenced this in commit 35fa9feec2 on May 10, 2020PastaPastaPasta referenced this in commit 3d73de3381 on May 10, 2020ckti referenced this in commit ea688a5fbd on Mar 28, 2021MarcoFalke locked this on Sep 8, 2021
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC
More mirrored repositories can be found on mirror.b10c.me