Net: Fixed a race condition when disabling the network.
Summary:
This change addresses a race condition where setnetworkactive=false wouldn't always disconnect all peers.
Before this change, the following could happen:
- Thread A -- Begins connecting to a node.
- Thread B -- Sets kNetworkActive=false and disconnects connected nodes.
- Thread A -- Finishes connecting and adds node to list of connected nodes.
The node that was connected from Thread A remains connected and active,
even though kNetworkActive=false.
To fix the race, disconnections when kNetworkActive=false are now handled in the main network loop.
fixes #13038
This is a backport of core PR13212 and include elements of PR10824
Test Plan:
make check
Reviewers: #bitcoin_abc, jasonbcox
Reviewed By: #bitcoin_abc, jasonbcox
Subscribers: teamcity
Differential Revision: https://reviews.bitcoinabc.org/D1878