bitpay / bitcore-node

Extensible full node using Bitcore
https://bitcore.io/
Other
352 stars 644 forks source link

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

Open markasoftware opened 7 years ago

markasoftware commented 7 years ago

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

dav1app commented 7 years ago

Having the same problem here. :/

markasoftware commented 7 years ago

@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.

davidraedev commented 7 years ago

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 commented 7 years ago

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

xelawafs commented 6 years ago

@daraeman what actual figure did you set?

davidraedev commented 6 years ago

@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.

xelawafs commented 6 years ago

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

charleslcso commented 6 years ago

@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 commented 6 years ago

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

DaShak commented 6 years ago

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

NeerajThapliyal commented 6 years ago

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.