<!-- Describe the issue -->
Running the RPC call importmulti with a xpub key with very large range results in a timeout error and seems to ultimately fail to import all addresses. Re-running the same RPC line may succeed in importing the missing addresses but not always.
Expected behavior
I run this RPC $ bitcoin-cli -rpcwallet=wallet-my-test-wallet.dat importmulti '[{"desc": "sh(wpkh(xpub6EcgD73U5aQe8F9k1VQmz3bDdnMmgNAouVixdsKVC9YTJb1BNPPq9jSCuDArzxzj2JAWcGyL9sJofgLQHAYovQqCibh3ovuWVtwiagp1x7d/*))#9fdjk2ls", "range": [0, 999999], "timestamp": "now", "watchonly": true}]' '{"rescan": false}'
I'd expect it to return nothing and import all those addresses.
<!--- What behavior did you expect? -->
Actual behavior
The RPC call runs for a couple of minutes and fails with the follow error:
error: Could not connect to the server 127.0.0.1:8332 (error code 0 - "timeout reached")
Make sure the bitcoind server is running and that you are connecting to the correct RPC port.
If I re-run the same RPC call then the call may return without the error message.
Other RPC calls (e.g. getbestblockhash) work as normal.
<!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->
To reproduce
The issue is reproducible every time. With a new empty wallet file (my-test-wallet.dat), run this:
$ bitcoin-cli -rpcwallet=wallet-my-test-wallet.dat importmulti '[{"desc": "sh(wpkh(xpub6EcgD73U5aQe8F9k1VQmz3bDdnMmgNAouVixdsKVC9YTJb1BNPPq9jSCuDArzxzj2JAWcGyL9sJofgLQHAYovQqCibh3ovuWVtwiagp1x7d/*))#9fdjk2ls", "range": [0, 999999], "timestamp": "now", "watchonly": true}]' '{"rescan": false}'
Warning: this will make the wallet file become about 1GB in size.
Importing 999999 addresses seems to never succeed no matter how many times its retried. Importing 500000 addresses seems to succeed after re-running the command once.
<!--- How reliably can you reproduce the issue, what are the steps to do so? -->
System information
<!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->
Bitcoin Core 0.19.0.1, binary downloaded from bitcoincore.org
<!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->
$ uname -a
Linux hostname 4.4.0-142-generic [#168](/bitcoin-bitcoin/168/)-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Using internal hard disk
<!-- GUI-related issue? What is your operating system and its version? If Linux, what is your desktop environment and graphical shell? -->
<!-- Any extra information that might be useful in the debugging process. -->
<!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->