Skip to content

Conversation

@jamesob
Copy link
Contributor

@jamesob jamesob commented Jan 18, 2019

Currently, the potential for a deadlock exists if ActivateBestChain() is called from within the ValidationInterface scheduler thread. This is because ABC itself avoids overrunning the VI queue by waiting for it to drain once it has passed a certain depth.

To avoid this (or at least disallow it during CI runs), this change introduces thread_local state that gets set to indicate execution on ValidationInterface threads. If we've compiled with DEBUG_LOCKORDER, calling ABC from within a VI thread throws an exception. A small, necessary refactoring on CMainSignals is included.

This changeset also includes a commit from #13168 that limits the platforms where we can rely on the use of thread_local.

@jamesob jamesob force-pushed the 2019-01-avoid-validationqueue-deadlock branch from af05222 to 76d0fa3 Compare January 18, 2019 19:11
@jamesob jamesob force-pushed the 2019-01-avoid-validationqueue-deadlock branch 2 times, most recently from 37f3992 to c024cc9 Compare January 18, 2019 19:48
@promag
Copy link
Contributor

promag commented Jan 19, 2019

Restarted appveyor, unrelated error.

@jamesob jamesob force-pushed the 2019-01-avoid-validationqueue-deadlock branch from c024cc9 to 5a18208 Compare January 22, 2019 14:31
@jamesob
Copy link
Contributor Author

jamesob commented Jan 22, 2019

Pushed an update futureproofing all calls to SyncWithValidationInterfaceQueue() (changes).

@jamesob jamesob force-pushed the 2019-01-avoid-validationqueue-deadlock branch 2 times, most recently from 7c01deb to 6f330dc Compare January 22, 2019 15:44
Since ActivateBestChain will in certain cases block in order to allow the
ValidationInterface queue to drain, it cannot safely be called from within
ValidationInterface callbacks. This patch adds assertions preventing that when
DEBUG_LOCKORDER.

We slightly rework the ValidationInterface class, adding an
`AddToProcessQueue()` method that handles scheduling a callback. When the
scheduling queue is initiated, we make the thread aware it's managed by
ValidationInterface.
Also adds default constructor and destructor to CMainSignals to avoid build
errors due to the forward declaration of MainSignalsInstance.
@jamesob jamesob force-pushed the 2019-01-avoid-validationqueue-deadlock branch from 6f330dc to 93e09ee Compare January 22, 2019 16:08
@jamesob
Copy link
Contributor Author

jamesob commented Jan 22, 2019

I've taken @practicalswift's advice on declaration conditional on #ifdef DEBUG_LOCKORDER but I kinda hate how many ifdefs that's introduced.

@jamesob
Copy link
Contributor Author

jamesob commented Jan 22, 2019

We discussed a better approach today on IRC (http://www.erisian.com.au/bitcoin-core-dev/log-2019-01-22.html), which is to conditionally move all Schedule tasks to blocking execution (instead of executing them on a separate thread) in the presence of some flag - that way we'll be able to make use of all the existing deadlock detection utilities when, say, running CI tests.

@jamesob jamesob closed this Jan 22, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants