The `dumpwallet` RPC command throws an error at the signet node and stops it.
~~This does not happen in mainnet or testnet, where the command worked successfully in my tests..~~
Originally this error was only happening on signet, but it also happened on testnet after it worked successfully for a while.

**Expected behavior**

The RPC `dumpwallet` command is expected to return a success message and create the dump file that contains the private keys.

**Actual behavior**

The command returns an error on client side (`bitcoin-cli`):
`error: timeout on transient error: Could not connect to the server 127.0.0.1:38332 (error code 1 - "EOF reached")
Make sure the bitcoind server is running and that you are connecting to the correct RPC port.`

And it throws an error at the signet node and stops it.

```
POTENTIAL DEADLOCK DETECTED
Previous lock order was:
  'cs_wallet' in wallet/wallet.cpp:2860 (in thread 'httpworker.1')
  (2) '::cs_main' in node/interfaces.cpp:687 (in thread 'httpworker.1')
  'm_node.mempool->cs' in node/interfaces.cpp:687 (in thread 'httpworker.1')
  'cs_wallet' in wallet/wallet.cpp:1204 (in thread 'httpworker.1')
  (1) 'cs_KeyStore' in script/signingprovider.cpp:165 (in thread 'httpworker.1')
Current lock order is:
  'wallet.cs_wallet' in wallet/rpcdump.cpp:743 (in thread 'httpworker.3')
  (1) 'spk_man.cs_KeyStore' in wallet/rpcdump.cpp:743 (in thread 'httpworker.3')
  (1) 'spk_man->cs_KeyStore' in wallet/wallet.cpp:2303 (in thread 'httpworker.3')
  (2) 'cs_main' in node/interfaces.cpp:493 (in thread 'httpworker.3')
Assertion failed: detected inconsistent lock order for 'cs_main' in node/interfaces.cpp:493 (in thread 'httpworker.3'), details in debug log.
Aborted (core dumped)
```

**To reproduce**

Start the node on signet mode:
`bitcoind -signet`

And dump an existing wallet:
`bitcoin-cli -signet -rpcwallet="legacy_wallet_01" dumpwallet "filename"`

**System information**

The bitcoin node was compiled from master (commit: `df2b5dadfb2dc21b05e5a60b71987fb5b96201f5`)
Ubuntu 20.04, 8 CPUs, 12 GiB RAM and SSD.

"\nImport addresses/scripts (with private or public keys, redeem script (P2SH)), optionally rescanning the blockchain from the earliest creation time of the imported scripts. Requires a new wallet backup.\n"
                "If an address/script is imported without all of the private keys required to spend from that address, it will be watchonly. The 'watchonly' option must be set to true in this case or a warning will be returned.\n"
                "Conversely, if all the private keys are provided and the address/script is spendable, the watchonly option must be set to false, or a warning will be returned.\n"
            "\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
            "may report that the imported keys, addresses or scripts exist but related transactions are still missing.\n"
            "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
                {
                    {"requests", RPCArg::Type::ARR, RPCArg::Optional::NO, "Data to be imported",
                        {
                            {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
                                {
                                    {"desc", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Descriptor to import. If using descriptor, do not also provide address/scriptPubKey, scripts, or pubkeys"},
                                    {"scriptPubKey", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of scriptPubKey (string for script, json for address). Should not be provided if using a descriptor",
                                        /* ", {"\"<script>\" | { \"address\":\"<address>\" }", "string / json"}
                                    },
                                    {"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO, "Creation time of the key expressed in " + UNIX_EPOCH_TIME + ",\n"
        "                                                              or the string \"now\" to substitute the current synced blockchain time. The timestamp of the oldest\n"
        "                                                              key will determine how far back blockchain rescans need to begin for missing wallet transactions.\n"
        "                                                              \"now\" can be specified to bypass scanning, for keys which are known to never have been used, and\n"
        "                                                              0 can be specified to scan the entire blockchain. Blocks up to 2 hours before the earliest key\n"
        "                                                              creation time of all keys being imported by the importmulti call will be scanned.",
                                        /* ", {"timestamp | \"now\"", "integer / string"}
                                    },
                                    {"redeemscript", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Allowed only if the scriptPubKey is a P2SH or P2SH-P2WSH address/scriptPubKey"},
                                    {"witnessscript", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Allowed only if the scriptPubKey is a P2SH-P2WSH or P2WSH address/scriptPubKey"},
                                    {"pubkeys", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "Array of strings giving pubkeys to import. They must occur in P2PKH or P2WPKH scripts. They are not required when the private key is also provided (see the \"keys\" argument).",
                                        {
                                            {"pubKey", RPCArg::Type::STR, RPCArg::Optional::OMITTED, ""},
                                        }
                                    },