HomePhabricator

Fix nullptr clientModel access during shutdown

Description

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.

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D17682

Details

Provenance
furszy <matiasfurszyfer@protonmail.com>Authored on Feb 28 2024, 12:47
FabienCommitted on Fri, Feb 21, 13:57
FabienPushed on Fri, Feb 21, 13:58
Reviewer
Restricted Project
Differential Revision
D17682: Fix nullptr clientModel access during shutdown
Parents
rABC4261e4fe94d7: [chronik] Fix handling of -chronikelectrummaxhistory
Branches
Unknown
Tags
Unknown