bitcoin: bitcoin-qt crashes if it can't listen on the port it wants to

I created new folders ~/.bitcoin2 and ~/.bitcoin3, then ran bitcoin-qt using both of them as data directories.

The first one ran fine:

qt/bitcoin-qt -datadir=/home/chris/.bitcoin2

I left the first one running. The second one crashed in various ways:

$ qt/bitcoin-qt -datadir=/home/chris/.bitcoin3
Error: Unable to bind to 0.0.0.0:8333 on this computer. Bitcoin Core is probably already running.
Error: Failed to listen on any port. Use -listen=0 if you want this.
Segmentation fault

$ qt/bitcoin-qt -datadir=/home/chris/.bitcoin3
Error: Unable to bind to 0.0.0.0:8333 on this computer. Bitcoin Core is probably already running.
Error: Failed to listen on any port. Use -listen=0 if you want this.
free(): double free detected in tcache 2
Aborted

$ qt/bitcoin-qt -datadir=/home/chris/.bitcoin3
Error: Unable to bind to 0.0.0.0:8333 on this computer. Bitcoin Core is probably already running.
Error: Failed to listen on any port. Use -listen=0 if you want this.
corrupted size vs. prev_size in fastbins
Aborted

I would expect it to complain about the unavailable port, but not to crash in such random ways.

This is bitcoin built against git tag v24.0rc2.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

The crash doesn’t happen if I use bitcoind. I get a clean shutdown with bitcoind:

$ ./bitcoind -connect=0 -server=1 -datadir=d1
2022-10-20T16:29:41Z Bitcoin Core version v24.0.0rc2 (release build)
2022-10-20T16:29:41Z InitParameterInteraction: parameter interaction: -connect set -> setting -dnsseed=0
2022-10-20T16:29:41Z InitParameterInteraction: parameter interaction: -connect set -> setting -listen=0
2022-10-20T16:29:41Z InitParameterInteraction: parameter interaction: -listen=0 -> setting -upnp=0
2022-10-20T16:29:41Z InitParameterInteraction: parameter interaction: -listen=0 -> setting -natpmp=0
2022-10-20T16:29:41Z InitParameterInteraction: parameter interaction: -listen=0 -> setting -discover=0
2022-10-20T16:29:41Z InitParameterInteraction: parameter interaction: -listen=0 -> setting -listenonion=0
2022-10-20T16:29:41Z InitParameterInteraction: parameter interaction: -listen=0 -> setting -i2pacceptincoming=0
2022-10-20T16:29:41Z Using the 'sse4(1way),sse41(4way),avx2(8way)' SHA256 implementation
2022-10-20T16:29:41Z Using RdSeed as an additional entropy source
2022-10-20T16:29:41Z Using RdRand as an additional entropy source
2022-10-20T16:29:41Z Default data directory /home/me/.bitcoin
2022-10-20T16:29:41Z Using data directory /home/me/Programs/bitcoin.clone/src/d1
2022-10-20T16:29:41Z Config file: /home/me/Programs/bitcoin.clone/src/d1/bitcoin.conf (not found, skipping)
2022-10-20T16:29:41Z Command-line arg: connect="0"
2022-10-20T16:29:41Z Command-line arg: datadir="d1"
2022-10-20T16:29:41Z Command-line arg: server="1"
2022-10-20T16:29:41Z Using at most 125 automatic connections (1024 file descriptors available)
2022-10-20T16:29:41Z Warning: relative datadir option 'd1' specified, which will be interpreted relative to the current working directory '/home/me/Programs/bitcoin.clone/src'. This is fragile, because if bitcoin is started in the future from a different location, it will be unable to locate the current data files. There could also be data loss if bitcoin is started while in a temporary directory.
2022-10-20T16:29:41Z Using 16 MiB out of 16 MiB requested for signature cache, able to store 524288 elements
2022-10-20T16:29:41Z Using 16 MiB out of 16 MiB requested for script execution cache, able to store 524288 elements
2022-10-20T16:29:41Z Script verification uses 11 additional threads
2022-10-20T16:29:41Z scheduler thread start
2022-10-20T16:29:41Z [libevent:warning] getaddrinfo: address family for nodename not supported
2022-10-20T16:29:41Z Binding RPC on address ::1 port 8332 failed.
2022-10-20T16:29:41Z Binding RPC on address 127.0.0.1 port 8332 failed.
2022-10-20T16:29:41Z Unable to bind any endpoint for RPC server
2022-10-20T16:29:41Z Error: Unable to start HTTP server. See debug log for details.
Error: Unable to start HTTP server. See debug log for details.
2022-10-20T16:29:41Z Shutdown: In progress...
2022-10-20T16:29:41Z scheduler thread exit
2022-10-20T16:29:41Z Shutdown: done

How about this?

qt/bitcoin-qt -connect=0 -server=1 -datadir=d1

That combination of options seems to provoke the crash for me every time, whereas specifying a random unused rpcport allows it to run without crashing:

qt/bitcoin-qt -connect=0 -server=1 -datadir=d1 -rpcport=9393