Fixing #800.
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.