Page MenuHomePhabricator

Fix nullptr clientModel access during shutdown
ClosedPublic

Authored by Fabien on Fri, Feb 21, 13:09.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC2f1230a53610: Fix nullptr clientModel access during shutdown
Summary
During shutdown, already queue events dispatched from the backend such
'numConnectionsChanged' and 0networkActiveChanged' could try to access
the clientModel object, which might not exist because we manually delete
it inside 'BitcoinApplication::requestShutdown()'.

This happen because boost does not clears the queued events when they arise
concurrently with the signal disconnection (see https://www.boost.org/doc/libs/1_55_0/doc/html/signals2/thread-safety.html).
From the docs:

    "Note that since we unlock the connection's mutex before executing its associated slot, it is possible a slot will still be executing after it has been disconnected by a connection::disconnect(), if the disconnect was called concurrently with signal invocation."
    "The fact that concurrent signal invocations use the same combiner object means you need to insure any custom combiner you write is thread-safe"

So, we need to guard clientModel before accessing it at the handler side.

Backport of core-gui#801.

Test Plan
ninja all check-all

On OSX, run the Qt with Chronik enabled, let it sync a bit then kill it. Check it doesn't segfault upon shutdown.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable