Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35579. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Friendly ping @w0xlt, would like to know what you think :) @pinheadmz I was unable to actually discover the cause of #35544 (comment), it's really difficult to detect race-conditions like this :/ . But I think it could be fixed by this PR. Were you able to trigger the failing test multiple times? If so, can you try to trigger it with this path to see if it works?? :) |
|
While this change seems fine and correct, looking at the failed test, I think the test itself is also incorrect. The test is supposed to have the 2 calls conflict during the rescan phase, but the rescan is not actually that slow because its only scanning a few hundred blocks with few relevant things in those blocks, so the rescan goes pretty fast. The way to slow down a rescan is to mine a ton of blocks, each of which have something relevant to the wallet. |
There was a problem hiding this comment.
ACK 336f5a7
Regarding the test, it really could be improved.
The patch below mines 5000 blocks paying to an address derived from the descriptor being imported, so the rescan has relevant wallet work.
It also removes the two-worker race between competing imports. The test still uses one background thread to keep importdescriptors in flight, but it waits until getwalletinfo()["scanning"] confirms an active rescan before sending the conflicting RPC, making it less timing-dependent.
Measurements on my machine:
Before:
Full test: 10.96s
rescan_wallet rescan: 2ms
After:
Full test: 17.37s
rescan_wallet primary rescan: 457ms
diff
diff --git a/test/functional/wallet_importdescriptors.py b/test/functional/wallet_importdescriptors.py
index f9429079bb..22f35b1f36 100755
--- a/test/functional/wallet_importdescriptors.py
+++ b/test/functional/wallet_importdescriptors.py
@@ -16,7 +16,6 @@ variants.
and test the values returned."""
import concurrent.futures
-import threading
import time
from test_framework.blocktools import COINBASE_MATURITY
@@ -128,41 +127,31 @@ class ImportDescriptorsTest(BitcoinTestFramework):
w_import = self.nodes[0].create_new_rpc_connection(mode="AUTHPROXY") / f"wallet/{wallet_name}"
- with concurrent.futures.ThreadPoolExecutor(max_workers=2) as thread:
+ with concurrent.futures.ThreadPoolExecutor(max_workers=1) as thread:
w_rescan = self.nodes[0].create_new_rpc_connection(mode="AUTHPROXY") / f"wallet/{wallet_name}"
- w_conflict = self.nodes[0].create_new_rpc_connection(mode="AUTHPROXY") / f"wallet/{wallet_name}"
- # Use an xprv with timestamp=0 and a large key-range to trigger a slow full rescan that stays in-flight
- slow_desc = [{"desc": descsum_create("pkh(" + xpriv + "/0h/*h)"),
- "timestamp": 0, "range": [0, 10000]}]
- conflicting_desc = [{"desc": descsum_create("pkh(" + xpriv + "/1h/*h)"),
- "timestamp": 0, "range": [0, 10000]}]
-
- start = threading.Barrier(3)
-
- def import_after_barrier(wallet, descriptors):
- start.wait(timeout=10)
- return wallet.importdescriptors(descriptors)
-
- imports = [
- thread.submit(import_after_barrier, w_rescan, slow_desc),
- thread.submit(import_after_barrier, w_conflict, conflicting_desc),
- ]
- start.wait(timeout=10)
-
- # One importdescriptor call must hold WalletRescanReserver while the other fails immediately.
- num_errors = 0
- num_success = 0
- for future in concurrent.futures.as_completed(imports, timeout=30 * self.options.timeout_factor):
- try:
- assert_equal(future.result(), [{'success': True}])
- num_success += 1
- except JSONRPCException as e:
- assert_equal(e.error["code"], -4)
- assert_equal(e.error["message"], "Wallet is currently rescanning. Abort existing rescan or wait.")
- num_errors += 1
-
- assert_equal(num_success, 1)
- assert_equal(num_errors, 1)
+ slow_desc_str = descsum_create("pkh(" + xpriv + "/0h/*h)")
+ relevant_address = self.nodes[0].deriveaddresses(slow_desc_str, [0, 0])[0]
+
+ num_relevant_blocks = 5000
+ # Mine blocks that are relevant to the descriptor being imported, so
+ # the rescan stays in-flight long enough to test the RPC conflict.
+ self.generatetoaddress(self.nodes[0], num_relevant_blocks, relevant_address)
+
+ slow_desc = [{"desc": slow_desc_str, "timestamp": 0, "range": [0, 10000]}]
+ rescanning = thread.submit(w_rescan.importdescriptors, slow_desc)
+
+ def rescan_in_progress():
+ if rescanning.done():
+ raise AssertionError("importdescriptors rescan finished before the conflicting RPC could be tested")
+ scanning = w_import.getwalletinfo()["scanning"]
+ return isinstance(scanning, dict) and 0 < scanning["progress"] < 0.95
+
+ self.wait_until(rescan_in_progress, timeout=30 * self.options.timeout_factor)
+
+ assert_raises_rpc_error(-4, "Wallet is currently rescanning. Abort existing rescan or wait.",
+ w_import.importdescriptors,
+ [{"desc": other_desc, "timestamp": "now"}])
+ assert_equal(rescanning.result(timeout=30 * self.options.timeout_factor), [{'success': True}])
# After the rescan finishes, any importdescriptors should succeed.
result = w_import.importdescriptors([{"desc": other_desc, "timestamp": "now"}])
@@ -180,8 +169,8 @@ class ImportDescriptorsTest(BitcoinTestFramework):
importing = thread.submit(w_import.importdescriptors, descriptor)
- # Keep trying because an abort before ScanForWalletTransactions starts
- # is reset when the scan loop begins.
+ # Keep trying until the abort lands while importdescriptors holds the
+ # wallet rescan reservation.
abort_succeeded = False
abort_deadline = time.time() + 30 * self.options.timeout_factor
while not importing.done() and time.time() < abort_deadline:
Are we sure about this? IIRC we were already doing this for a previous version of the test and it caused some failures. |
b27a0bc to
9e62e4b
Compare
| // Make sure the results are valid at least up to the most recent block | ||
| // the user could have gotten from another RPC command prior to now | ||
| wallet.BlockUntilSyncedToCurrentChain(); | ||
|
|
There was a problem hiding this comment.
Maybe worth adding some comment explaining the ordering to avoid introducing this race condition again in the future.
Something like:
// Reserve the rescan slot before any operation that can block on cs_wallet,
// so concurrent imports are rejected immediately rather than causing a race condition.
WalletRescanReserver reserver(*pwallet);
There was a problem hiding this comment.
will take if re-touching
|
ACK 9e62e4b |
…4e48e968a 114e48e968a kernel: Add script tracer 54e1a95a12e Merge bitcoin/bitcoin#35719: ci: disable Qt build in OpenBSD cross job b0e09511586 ci: disable Qt build in OpenBSD cross job 734c34bafda Merge bitcoin/bitcoin#35427: depends: Build `qt` and `qrencode` packages on OpenBSD ee61b11a9e7 Merge bitcoin/bitcoin#35200: node: smooth oversized `dbcache` warnings e3554bf361f Merge bitcoin/bitcoin#35579: wallet: reserve walletrescan before checking wallet is at the tip 11ae4265522 Merge bitcoin/bitcoin#35715: cmake: Fix WITH_EXTERNAL_LIBMULTIPROCESS + BUILD_FUZZ_BINARY e544413c0de Merge bitcoin/bitcoin#32763: wallet: Replace CWalletTx::mapValue and vOrderForm with explicit class members fe1cb6e40d7 Merge bitcoin/bitcoin#35690: wallet: Introduce WalletError with machine-readable error code 441f3114f57 Merge bitcoin/bitcoin#35659: Clarify supported *BSD releases and drop outdated workarounds 0399df827c6 Merge bitcoin/bitcoin#35708: depends: capnp 1.5.0 1ab1fdd4696 Merge bitcoin/bitcoin#35705: bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase db35b9238fc ipc # build: Fix fuzz target CMakeLists.txt for external libmultiprocess d18fec892e2 Merge bitcoin/bitcoin#35698: doc: Update enum class constant naming style guide a2e4cd7ad2a depends: capnp 1.5.0 7508ac319d9 bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase 907e284e303 Merge bitcoin/bitcoin#35701: test: Remove `mock_process.cpp` c8459b6bdcd Merge bitcoin/bitcoin#35568: txospenderindex: disable bloom filters to optimize disk usage 63c5f9d22c0 test: Remove `mock_process.cpp` ef101b04a8d Merge bitcoin/bitcoin#35655: wallet: Use in-memory SQLite for temporary wallet in exportwatchonlywallet b6becf3534c Merge bitcoin/bitcoin#35684: Update libmultiprocess subtree to add `max_connections` option 930f25050f7 Merge bitcoin/bitcoin#35700: doc: archive release notes for v29.4 9b2b3f4ec6f doc: archive release notes for v29.4 297fd1489bb Merge bitcoin/bitcoin#35412: ci: add NetBSD Clang cross job e314869066b Merge bitcoin/bitcoin#35695: Remove myself as security contact e3d67a5eae5 Merge bitcoin/bitcoin#35691: chainparams: delete my DNS seed a8223bb4e62 wallet: Introduce WalletError with machine-readable error code fad5809cb92 doc: Update enum class constant naming style guide 7d8137c1417 Merge bitcoin/bitcoin#34897: indexes: Don't commit ahead of the flushed chainstate 629df81e4c6 Remove myself as security contact d164a043426 node: smooth oversized `-dbcache` warnings d9080639804 chainparams: delete my DNS seed e9ed898a0da validation: Don't use m_chain.Tip() in FlushStateToDisk 3679f1ecf5e index: Don't commit ahead of the flushed chainstate 65735728a5a index: Remove return value from Commit() 09c06960c6a validation: track last flushed block 13c02b5466d test: add test for index commits ahead of the last flushed block c43b7a1115f ci: add netBSD cross CI job 699c21aea47 depends: add netbsd_LDFLAGS 777d23f25c7 test: add regression test for in-memory SQLiteDatabase reopen d1e7f8c986f wallet: use in-memory SQLite for temporary wallet in exportwatchonlywallet ee43743f126 wallet: store m_additional_flags in SQLiteDatabase to fix reopen path a9d1b652f32 Merge commit '707d0ded84563386f770ec17970834c65f8fa938' into pr/subtree-12 707d0ded845 Squashed 'src/ipc/libmultiprocess/' changes from 16bf05dea02..28e056576a3 2bab6bc73f2 refactor: Drop support for FreeBSD < 14 91b5c8a07c6 refactor: Remove FreeBSD-specific workaround 56701ff6d5c doc: Clarify supported *BSD releases 6d0ea4cf5bd doc: add release notes a2b1c86903a txospenderindex: disable bloom filters to optimize disk usage fed3cf6f0ed wallet: Replace CWalletTx's vOrderForm with specific fields 4f8823e8e11 wallet: Drop vOrderForm from CommitTransaction 9e62e4b1f34 test: slow down rescaning process a2b0bfcd854 wallet: Drop mapValue from CWalletTx cb99864c91c wallet: Throw if unknown entry is found in mapValue 98d5cdae663 wallet: Make CWalletTx "replaces_txid" and "replaced_by_txid" member variables 7ef8a6efc2a wallet: Make CWalletTx "comment" and "to" member variables 2155e913d3e wallet: Make CWalletTx "from" and "message" member variables c6ba98dcc8a wallet: Drop mapValue from CommitTransaction 00abb174a80 wallet: Pass comment and comment_to to CommitTransaction 1a219a37a21 wallet: Pass replaces_txid to CommitTransaction outside of mapValue 336f5a738b3 wallet: reserve walletrescan before checking wallet is at the tip a54ec373a69 depends: Build `qt` and `qrencode` packages for OpenBSD hosts git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: 114e48e968a087f74c1ab611ac2a31a9266812e1
…king wallet is at the tip 453d653 test: slow down rescaning process (Pol Espinasa) 1ee446f wallet: reserve walletrescan before checking wallet is at the tip (Pol Espinasa) Pull request description: `ImportDescriptors` rpc has a race condition where two imports running in parallel can both succeed or fail one of them. The race happens when there are two threads A and B trying to importdescriptors at the same time. 1. Thread A calls `BlockUntilSyncedToCurrentChain()` (holding `cs_wallet` fast, no contention) and then `reserve()`, acquiring the `WalletRescanReserver`. It proceeds to `ProcessDescriptorImport()`, which holds `cs_wallet` for an extended time (specially on slow machines) while importing descriptors. 2. B reaches `BlockUntilSyncedToCurrentChain()`, which internally does `WITH_LOCK(cs_wallet, ...)`. Since A holds `cs_wallet`, B blocks here for the entire duration of Thread A's descriptors import. 3. Then A finishes importing, releases `cs_wallet`, rescans (fast in regtest), and sets `fScanningWallet = false`. 4. B can now continue in `BlockUntilSyncedToCurrentChain()` acquiring `cs_wallet`, and then calls `reserve()` which succeeds because `fScanningWallet` is already `false`. Both imports succeed. I don't think the behavior is problematic at all from a usability PoV, but it can be a bad UX if some imports fails and other's no. It also makes testing difficult as race conditions are not easy to test. This PR fixes it by calling `reserver.reserve()` before `cs_wallet` is locked, so multiple threads will be aware of currently imports before being stuck at any point. So only one `importdescriptor` call can be done at the same time. I think this should fix bitcoin/bitcoin#35544 (comment) ACKs for top commit: achow101: ACK 453d653 nebula-21: ACK 453d653 w0xlt: lgtm reACK 453d653 Tree-SHA512: be0027e1a7b77252ed9fb514c3b3311d6905903d4b0bfc1021a1e1c2bb06872ef599647ff8a4536929240717ae9db62fb75374f629cd3046c7192e2b8b4d7344
…d9ec7f3d4 70d9ec7f3d4 Merge bitcoin/bitcoin#34538: net: advertise -externalip addresses 7bff765d514 Merge bitcoin/bitcoin#35639: external_signer: validate fingerprint from enumerate response 773b1c9aa58 Merge bitcoin/bitcoin#35572: coins: make cursor iteration DB-only 8d9e4f8dbd8 Merge bitcoin/bitcoin#35633: wallet: avoid call bumpfeediscount with negative values c4216e885a6 Merge bitcoin/bitcoin#35723: fuzz: Drop unnecessary mutexes 240d5f743aa fuzz: Drop unnecessary mutexes cf0368fb76e Merge bitcoin/bitcoin#35720: ipc: Update libmultiprocess subtree and drop fuzz test workaround 2d4065d1fe4 Merge bitcoin/bitcoin#35718: ci: Update lint container dependencies 8d9fbf76664 Merge bitcoin/bitcoin#35380: kernel: expose witness stack and scriptSig for btck_TransactionInput fab8eeed82c fuzz: clang-format LIMITED_WHILE fa0d777ce2a fuzz: Clang-format LIMITED_WHILE like while fa1a9bde5a6 fuzz: Remove unused workaround after fix in libmultiprocess byte-span serializer fa55385ab36 fuzz: Use LIMITED_WHILE over for-loop with consumed size integral fa911d815db Merge commit '6d5f753921578eefdd3fce64cfc8ee7951b6cbc4' into HEAD 6d5f7539215 Squashed 'src/ipc/libmultiprocess/' changes from 28e056576a..e8de5c7b68 900a7785bf5 ci: use Ubuntu 26.04 for lint container 058a73a0aea ci: use uv 11.x 14f4ddcb554 ci: mypy 2.3.0 54e1a95a12e Merge bitcoin/bitcoin#35719: ci: disable Qt build in OpenBSD cross job b0e09511586 ci: disable Qt build in OpenBSD cross job 734c34bafda Merge bitcoin/bitcoin#35427: depends: Build `qt` and `qrencode` packages on OpenBSD ee61b11a9e7 Merge bitcoin/bitcoin#35200: node: smooth oversized `dbcache` warnings e3554bf361f Merge bitcoin/bitcoin#35579: wallet: reserve walletrescan before checking wallet is at the tip 11ae4265522 Merge bitcoin/bitcoin#35715: cmake: Fix WITH_EXTERNAL_LIBMULTIPROCESS + BUILD_FUZZ_BINARY e544413c0de Merge bitcoin/bitcoin#32763: wallet: Replace CWalletTx::mapValue and vOrderForm with explicit class members fe1cb6e40d7 Merge bitcoin/bitcoin#35690: wallet: Introduce WalletError with machine-readable error code 441f3114f57 Merge bitcoin/bitcoin#35659: Clarify supported *BSD releases and drop outdated workarounds 0399df827c6 Merge bitcoin/bitcoin#35708: depends: capnp 1.5.0 1ab1fdd4696 Merge bitcoin/bitcoin#35705: bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase db35b9238fc ipc # build: Fix fuzz target CMakeLists.txt for external libmultiprocess d18fec892e2 Merge bitcoin/bitcoin#35698: doc: Update enum class constant naming style guide a2e4cd7ad2a depends: capnp 1.5.0 7508ac319d9 bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase 907e284e303 Merge bitcoin/bitcoin#35701: test: Remove `mock_process.cpp` c8459b6bdcd Merge bitcoin/bitcoin#35568: txospenderindex: disable bloom filters to optimize disk usage 63c5f9d22c0 test: Remove `mock_process.cpp` ef101b04a8d Merge bitcoin/bitcoin#35655: wallet: Use in-memory SQLite for temporary wallet in exportwatchonlywallet b6becf3534c Merge bitcoin/bitcoin#35684: Update libmultiprocess subtree to add `max_connections` option 930f25050f7 Merge bitcoin/bitcoin#35700: doc: archive release notes for v29.4 9b2b3f4ec6f doc: archive release notes for v29.4 297fd1489bb Merge bitcoin/bitcoin#35412: ci: add NetBSD Clang cross job e314869066b Merge bitcoin/bitcoin#35695: Remove myself as security contact e3d67a5eae5 Merge bitcoin/bitcoin#35691: chainparams: delete my DNS seed a8223bb4e62 wallet: Introduce WalletError with machine-readable error code fad5809cb92 doc: Update enum class constant naming style guide 7d8137c1417 Merge bitcoin/bitcoin#34897: indexes: Don't commit ahead of the flushed chainstate 629df81e4c6 Remove myself as security contact d164a043426 node: smooth oversized `-dbcache` warnings d9080639804 chainparams: delete my DNS seed e9ed898a0da validation: Don't use m_chain.Tip() in FlushStateToDisk 3679f1ecf5e index: Don't commit ahead of the flushed chainstate 65735728a5a index: Remove return value from Commit() 09c06960c6a validation: track last flushed block 13c02b5466d test: add test for index commits ahead of the last flushed block c43b7a1115f ci: add netBSD cross CI job 699c21aea47 depends: add netbsd_LDFLAGS 777d23f25c7 test: add regression test for in-memory SQLiteDatabase reopen d1e7f8c986f wallet: use in-memory SQLite for temporary wallet in exportwatchonlywallet ee43743f126 wallet: store m_additional_flags in SQLiteDatabase to fix reopen path a9d1b652f32 Merge commit '707d0ded84563386f770ec17970834c65f8fa938' into pr/subtree-12 707d0ded845 Squashed 'src/ipc/libmultiprocess/' changes from 16bf05dea02..28e056576a3 6667dc4eec7 kernel: expose scriptSig for btck_TransactionInput e6de3a2d3c7 kernel: expose witness stack for btck_TransactionInput 3ae3a94f2bd wallet: avoid call bumpfeediscount with negative values dab7f2c984b test: cover -externalip/onlynet interaction in functional test 657a5aa3f3d test: cover -externalip bypassing -onlynet 8c87e32bd39 net: let -externalip bypass -onlynet f4af02e827b net: add an add_even_if_unreachable argument to AddLocal 2bab6bc73f2 refactor: Drop support for FreeBSD < 14 91b5c8a07c6 refactor: Remove FreeBSD-specific workaround 56701ff6d5c doc: Clarify supported *BSD releases 6d0ea4cf5bd doc: add release notes a2b1c86903a txospenderindex: disable bloom filters to optimize disk usage 4c9de7d5b32 external_signer: validate fingerprint from enumerate response fed3cf6f0ed wallet: Replace CWalletTx's vOrderForm with specific fields 4f8823e8e11 wallet: Drop vOrderForm from CommitTransaction 9e62e4b1f34 test: slow down rescaning process a2b0bfcd854 wallet: Drop mapValue from CWalletTx cb99864c91c wallet: Throw if unknown entry is found in mapValue 98d5cdae663 wallet: Make CWalletTx "replaces_txid" and "replaced_by_txid" member variables 7ef8a6efc2a wallet: Make CWalletTx "comment" and "to" member variables 2155e913d3e wallet: Make CWalletTx "from" and "message" member variables c6ba98dcc8a wallet: Drop mapValue from CommitTransaction 00abb174a80 wallet: Pass comment and comment_to to CommitTransaction 1a219a37a21 wallet: Pass replaces_txid to CommitTransaction outside of mapValue 72db4accbf5 coins: drop stale cursor null checks 3d2f2d8de09 coins: pass UTXO stats view by reference 35aedb28236 coins: drop cursor from base view c6fbe2f66cf coins: pass DB view to cursor users 336f5a738b3 wallet: reserve walletrescan before checking wallet is at the tip a54ec373a69 depends: Build `qt` and `qrencode` packages for OpenBSD hosts git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: 70d9ec7f3d452789d04dce81dc02db0b3b778bb5
…king wallet is at the tip 9e62e4b1f346f70eaa23e83eff769b6e6cc04630 test: slow down rescaning process (Pol Espinasa) 336f5a738b3d89abb8dd7ebdc4b31ac12a6de85f wallet: reserve walletrescan before checking wallet is at the tip (Pol Espinasa) Pull request description: `ImportDescriptors` rpc has a race condition where two imports running in parallel can both succeed or fail one of them. The race happens when there are two threads A and B trying to importdescriptors at the same time. 1. Thread A calls `BlockUntilSyncedToCurrentChain()` (holding `cs_wallet` fast, no contention) and then `reserve()`, acquiring the `WalletRescanReserver`. It proceeds to `ProcessDescriptorImport()`, which holds `cs_wallet` for an extended time (specially on slow machines) while importing descriptors. 2. B reaches `BlockUntilSyncedToCurrentChain()`, which internally does `WITH_LOCK(cs_wallet, ...)`. Since A holds `cs_wallet`, B blocks here for the entire duration of Thread A's descriptors import. 3. Then A finishes importing, releases `cs_wallet`, rescans (fast in regtest), and sets `fScanningWallet = false`. 4. B can now continue in `BlockUntilSyncedToCurrentChain()` acquiring `cs_wallet`, and then calls `reserve()` which succeeds because `fScanningWallet` is already `false`. Both imports succeed. I don't think the behavior is problematic at all from a usability PoV, but it can be a bad UX if some imports fails and other's no. It also makes testing difficult as race conditions are not easy to test. This PR fixes it by calling `reserver.reserve()` before `cs_wallet` is locked, so multiple threads will be aware of currently imports before being stuck at any point. So only one `importdescriptor` call can be done at the same time. I think this should fix bitcoin/bitcoin#35544 (comment) ACKs for top commit: achow101: ACK 9e62e4b1f346f70eaa23e83eff769b6e6cc04630 nebula-21: ACK 9e62e4b1f346f70eaa23e83eff769b6e6cc04630 w0xlt: lgtm reACK 9e62e4b1f346f70eaa23e83eff769b6e6cc04630 Tree-SHA512: be0027e1a7b77252ed9fb514c3b3311d6905903d4b0bfc1021a1e1c2bb06872ef599647ff8a4536929240717ae9db62fb75374f629cd3046c7192e2b8b4d7344
ImportDescriptorsrpc has a race condition where two imports running in parallel can both succeed or fail one of them.The race happens when there are two threads A and B trying to importdescriptors at the same time.
Thread A calls
BlockUntilSyncedToCurrentChain()(holdingcs_walletfast, no contention) and thenreserve(), acquiring theWalletRescanReserver. It proceeds toProcessDescriptorImport(), which holdscs_walletfor an extended time (specially on slow machines) while importing descriptors.B reaches
BlockUntilSyncedToCurrentChain(), which internally doesWITH_LOCK(cs_wallet, ...). Since A holdscs_wallet, B blocks here for the entire duration of Thread A's descriptors import.Then A finishes importing, releases
cs_wallet, rescans (fast in regtest), and setsfScanningWallet = false.B can now continue in
BlockUntilSyncedToCurrentChain()acquiringcs_wallet, and then callsreserve()which succeeds becausefScanningWalletis alreadyfalse. Both imports succeed.I don't think the behavior is problematic at all from a usability PoV, but it can be a bad UX if some imports fails and other's no. It also makes testing difficult as race conditions are not easy to test.
This PR fixes it by calling
reserver.reserve()beforecs_walletis locked, so multiple threads will be aware of currently imports before being stuck at any point. So only oneimportdescriptorcall can be done at the same time.I think this should fix #35544 (comment)