Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Nov 28, 2017

PR #10286 introduced a few steps which are not robust to early shutdown in initialization.

Stumbled upon this with #11781, not sure if there are other scenarios that can trigger it, but it's good to harden against this in any case.

E.g.

$ src/bitcoind  -debuglogfile=/dfdf
Error: Could not open debug log file /dfdf
Program received signal SIGSEGV, Segmentation fault.
UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
82          g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
(gdb) bt
#0  UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
#1  0x00005555555a11fc in Shutdown () at /.../bitcoin/src/init.cpp:196
#2  0x00005555555961cc in AppInit (argc=<optimized out>, argv=<optimized out>) at /.../bitcoin/src/bitcoind.cpp:183
#3  0x0000555555596249 in main (argc=0, argv=0x555555ecf200) at /.../bitcoin/src/bitcoind.cpp:19

PR bitcoin#10286 introduced a few steps which are not robust to early shutdown
in initialization.

Stumbled upon this with bitcoin#11781, not sure if there are other scenarios
that can trigger it, but it's harden against this in any case.
@laanwj laanwj added the Docs label Nov 28, 2017
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In places where m_internals is used, what about adding:

assert(m_internals);

For instance, in RegisterValidationInterface().

@promag
Copy link
Contributor

promag commented Nov 28, 2017

Tested ACK d31e5c1.

@jnewbery
Copy link
Contributor

Tested ACK d31e5c1. Looks good to me.

Request review from @TheBlueMatt

@TheBlueMatt
Copy link
Contributor

Except for the peerLogic de-register, given where the validationinterface is given the scheduler in AppInitMain, I'm pretty confident it'd be pretty hard to hit this on current master. Still, good idea to make it more robust, utACK d31e5c1.

@laanwj
Copy link
Member Author

laanwj commented Nov 30, 2017

@TheBlueMatt I agree, if it wasn't for changes that error out sooner in AppInitMain, like #11781 we'd probably never have stumbled on these.

laanwj added a commit to laanwj/bitcoin that referenced this pull request Nov 30, 2017
…tion

d31e5c1 Fix shutdown in case of errors during initialization (Wladimir J. van der Laan)

Pull request description:

  PR bitcoin#10286 introduced a few steps which are not robust to early shutdown in initialization.

  Stumbled upon this with bitcoin#11781, not sure if there are other scenarios that can trigger it, but it's good to harden against this in any case.

  E.g.
  ```
  $ src/bitcoind  -debuglogfile=/dfdf
  Error: Could not open debug log file /dfdf
  Program received signal SIGSEGV, Segmentation fault.
  UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
  82          g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
  (gdb) bt
  #0  UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
  #1  0x00005555555a11fc in Shutdown () at /.../bitcoin/src/init.cpp:196
  #2  0x00005555555961cc in AppInit (argc=<optimized out>, argv=<optimized out>) at /.../bitcoin/src/bitcoind.cpp:183
  #3  0x0000555555596249 in main (argc=0, argv=0x555555ecf200) at /.../bitcoin/src/bitcoind.cpp:19
  ```

Tree-SHA512: 7dd9570a9803514a17781bfadf1edde47e96df4e852cce2f423cab422e005fb94d44e777af1a6ea5167b04a4d889e848ae7a61a7e0e94232247ddea32ee70fc8
@laanwj laanwj merged commit d31e5c1 into bitcoin:master Nov 30, 2017
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 29, 2020
…tion

d31e5c1 Fix shutdown in case of errors during initialization (Wladimir J. van der Laan)

Pull request description:

  PR bitcoin#10286 introduced a few steps which are not robust to early shutdown in initialization.

  Stumbled upon this with bitcoin#11781, not sure if there are other scenarios that can trigger it, but it's good to harden against this in any case.

  E.g.
  ```
  $ src/bitcoind  -debuglogfile=/dfdf
  Error: Could not open debug log file /dfdf
  Program received signal SIGSEGV, Segmentation fault.
  UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
  82          g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
  (gdb) bt
  #0  UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
  #1  0x00005555555a11fc in Shutdown () at /.../bitcoin/src/init.cpp:196
  #2  0x00005555555961cc in AppInit (argc=<optimized out>, argv=<optimized out>) at /.../bitcoin/src/bitcoind.cpp:183
  #3  0x0000555555596249 in main (argc=0, argv=0x555555ecf200) at /.../bitcoin/src/bitcoind.cpp:19
  ```

Tree-SHA512: 7dd9570a9803514a17781bfadf1edde47e96df4e852cce2f423cab422e005fb94d44e777af1a6ea5167b04a4d889e848ae7a61a7e0e94232247ddea32ee70fc8
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Feb 18, 2021
…hread

6cecb7b AddToWalletIfInvolvingMe should test pIndex, not posInBlock (furszy)
73499ff Add missing lock in CScheduler::AreThreadsServicingQueue() (Matt Corallo)
6d1a60e ValidationInterface compiler warning fix (furszy)
9e523a7 Fix shutdown in case of errors during initialization (Wladimir J. van der Laan)
207c17f Expose if CScheduler is being serviced, assert its not in EmptyQueue (Matt Corallo)
64c525b Otherwise threads will try to continue modifying data structures while the dump process is being executed. (Matt Corallo)
8022463 Support more than one CScheduler thread for serial clients (Matt Corallo)
6532fca Add default arg to CScheduler to schedule() a callback now (Matt Corallo)
d583d12 Give CMainSignals a reference to the global scheduler so that it can run some signals in the background later (Matt Corallo)
c26d18c Remove unused NotifyTransactionLock signal. (furszy)
2c9de45 Remove unused UpdatedTransaction signal and connected slot. (furszy)
8f38657 make ConnectBlock static in validation.cpp (furszy)

Pull request description:

  Another step forward in the wallet signals processing in the background thread + node validation <--> wallet separation long working paths.

   Adapting:
   * bitcoin#10178
   * bitcoin#10179
   * bitcoin#10221
   * bitcoin#10914
   * bitcoin#11783
   * Plus added an extra cleanup to the validation interface removing unused `NotifyTransactionLock` signal and its respective slots.

ACKs for top commit:
  Fuzzbawls:
    ACK 6cecb7b
  random-zebra:
    ACK 6cecb7b and merging...

Tree-SHA512: ac1c128cb3e4ec47c2803da68ca4d4b16164687fc790f3cc1d0761e73bd61b4edc681e2ce045e52564dd13a8279495e9058a6aae316196bd7ad9c97a07dd0b20
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Feb 15, 2022
…tion

d31e5c1 Fix shutdown in case of errors during initialization (Wladimir J. van der Laan)

Pull request description:

  PR bitcoin#10286 introduced a few steps which are not robust to early shutdown in initialization.

  Stumbled upon this with bitcoin#11781, not sure if there are other scenarios that can trigger it, but it's good to harden against this in any case.

  E.g.
  ```
  $ src/bitcoind  -debuglogfile=/dfdf
  Error: Could not open debug log file /dfdf
  Program received signal SIGSEGV, Segmentation fault.
  UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
  82          g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
  (gdb) bt
  #0  UnregisterValidationInterface (pwalletIn=0x0) at /.../bitcoin/src/validationinterface.cpp:82
  #1  0x00005555555a11fc in Shutdown () at /.../bitcoin/src/init.cpp:196
  #2  0x00005555555961cc in AppInit (argc=<optimized out>, argv=<optimized out>) at /.../bitcoin/src/bitcoind.cpp:183
  #3  0x0000555555596249 in main (argc=0, argv=0x555555ecf200) at /.../bitcoin/src/bitcoind.cpp:19
  ```

Tree-SHA512: 7dd9570a9803514a17781bfadf1edde47e96df4e852cce2f423cab422e005fb94d44e777af1a6ea5167b04a4d889e848ae7a61a7e0e94232247ddea32ee70fc8
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants