bitcore-node icon indicating copy to clipboard operation
bitcore-node copied to clipboard

Doesn't always wait for bitcoind to be fully started up

Open markasoftware opened this issue 8 years ago • 11 comments

When starting up bitcore-node now, I get the following error:

[2017-03-17T01:14:29.849Z] warn: Activating best chain...
[2017-03-17T01:14:34.855Z] warn: Activating best chain...
[2017-03-17T01:14:39.859Z] warn: Activating best chain...
[2017-03-17T01:14:44.866Z] warn: Activating best chain...
[2017-03-17T01:14:49.872Z] warn: Activating best chain...
[2017-03-17T01:14:54.879Z] warn: Activating best chain...
[2017-03-17T01:14:59.883Z] warn: Activating best chain...
[2017-03-17T01:15:04.895Z] warn: Activating best chain...
[2017-03-17T01:15:04.942Z] error: Failed to start services
[2017-03-17T01:15:04.942Z] error: RPCError: Activating best chain...
    at Bitcoin._wrapRPCError (/home/apg/apg-node/node_modules/bitcore-node/lib/services/bitcoind.js:449:13)
    at /home/apg/apg-node/node_modules/bitcore-node/lib/services/bitcoind.js:779:28
    at IncomingMessage.<anonymous> (/home/apg/apg-node/node_modules/bitcoind-rpc/lib/index.js:107:7)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
[2017-03-17T01:15:10.341Z] error: Failed to stop services: Error: bitcoind spawned process exited with status code: 1

It seems like bitcore is trying to send RPC calls before bitcoind is fully started up, as explained here: http://bitcoin.stackexchange.com/questions/40583/what-does-it-mean-error-code-28-message-activating-best-chain

markasoftware avatar Mar 17 '17 01:03 markasoftware

Having the same problem here. :/

dav1app avatar Sep 26 '17 13:09 dav1app

@jhoutromundo ouch :( unfortunately I never really fixed this issue. I ended up putting a hard-coded timeout in to wait 30 minutes before attempting to connect.

markasoftware avatar Sep 26 '17 16:09 markasoftware

I had this error intermittently as well. After some digging it appears to be this line causing the problem.

There is a hardcoded 60 time retry in the initial connect function, and if bitcoind hasn't finished starting up by that point bitcore (wrongly) assumes something has gone wrong.

You should be able to work around this by setting that retry value to something higher.

davidraedev avatar Sep 28 '17 01:09 davidraedev

Just changing that one line didn't actually solve it for me, I also changed the other one here and that solved it.

davidraedev avatar Sep 28 '17 08:09 davidraedev

@daraeman what actual figure did you set?

xelawafs avatar Jan 16 '18 04:01 xelawafs

@xelawafs Looks like I settled on 100,000, but it really just depends on your machine and the state of your data. I think I had it and 10,000 and had to up it since it occasionally still failed.

davidraedev avatar Jan 16 '18 04:01 davidraedev

I initially had it at 200, it failed. Bumped it up to 20000 and now it's back to syncing

xelawafs avatar Jan 16 '18 05:01 xelawafs

@daraeman

Just changing that one line didn't actually solve it for me, I also changed the other one here and that solved it.

What other parameter did you change? Opening the link you provided goes to the same line at

async.retry({times: 60, ...

charleslcso avatar Feb 13 '18 13:02 charleslcso

Got it. Two lines with the same content....

charleslcso avatar Feb 13 '18 13:02 charleslcso

Thanks to @daraeman and others who commented on increasing the hardcoded values for retries, as it worked for me.

This fix applies to another issue thread: https://github.com/bitpay/bitcore/issues/1434

DaShak avatar Jun 11 '18 21:06 DaShak

Thanks to @daraeman you save my day. i have changes in https://github.com/bitpay/bitcore-node/blob/97683d2ff1dd8e84bf9f7f338052cc0ed258961f/lib/services/bitcoind.js#L929 and https://github.com/bitpay/bitcore-node/blob/97683d2ff1dd8e84bf9f7f338052cc0ed258961f/lib/services/bitcoind.js#L884 line. change time to 60 to 200.

NeerajThapliyal avatar Aug 09 '18 08:08 NeerajThapliyal