Page MenuHomePhabricator

Net: Fixed a race condition when disabling the network.
ClosedPublic

Authored by deadalnix on Oct 4 2018, 12:09.

Details

Summary

This change addresses a race condition where setnetworkactive=false wouldn't always disconnect all peers.

Before this change, the following could happen:

  1. Thread A -- Begins connecting to a node.
  2. Thread B -- Sets kNetworkActive=false and disconnects connected nodes.
  3. 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

Diff Detail

Repository
rABC Bitcoin ABC
Branch
raceconditiondisablenet
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 3509
Build 5094: Bitcoin ABC Buildbot (legacy)
Build 5093: arc lint + arc unit