Why does bitcoind say "error: couldn't connect to server" for the first few minutes of boot-up?

9

0

After starting bitcoin from the command line, with:

./bitcoind -daemon

I immediately run the followup command:

./bitcoind getinfo

which gives me the following error:

error: couldn't connect to server

This error lasts from a few seconds to a few minutes depending on the machine.

Two questions:

  1. What is Bitcoin doing during this time, that causes this error (i.e. prevents the client from returning the results of getinfo)?
  2. Are there any steps I can take that will minimize this start-up time?

schulwitz

Posted 2014-01-10T10:12:50.800

Reputation: 285

Answers

11

The first thing Bitcoin-QT does is verify that the data stored on the disk is valid. Among other checks this includes verifying the last 288 blocks (the past two days in expectation). This task involves a large number of signature checks and will take some time to complete. Only after the startup checks have successfully completed will the connections to the Bitcoin Network be established and only then the client will start listening for incoming JSON-RPC requests.

cdecker

Posted 2014-01-10T10:12:50.800

Reputation: 7 878

3another gotcha - I was running the testnet. couldn't get bitcoin-cli to work until I added -testnet (i.e. bitcoin-cli -testnet getinfo)Peter Munnings 2015-09-14T08:05:13.427

@PeterMunnings: Good one, thanks. I had the same problem -- although I'm about 90% sure that it used to work without it before.Priidu Neemre 2016-10-01T15:04:43.937

If you add testnet=1 to your main bitcoin.conf then the bitcoin-cli will work with testnet without having to specify it on the command line. Add -testnet=0 on the command line to bypass that for mainnet.cdecker 2016-10-02T13:02:39.930