Repository navigation
Commit 359680b
committed
net: move cs_main up in FetchBlock to fix rpc assert crash
1. FetchBlock runs in a http worker thread. It acquires a PeerRef,
locks cs_main, then may later call BlockRequested which asserts
that CNodeState exists for the peer.
2. FinalizeNode may run in either the bitcoind or b-net threads. It
locks cs_main, fetches a PeerRef from RemovePeer, fetches a CNodeState,
and later removes it from m_node_states.
Because of the lock placement in FetchBlock, the http worker thread in 1)
can acquire a valid PeerRef and block while the b-net thread in 2) is
cleaning up the peer in FinalizeNode. When the worker thread later acquires
cs_main, it may crash in BlockRequested since no CNodeState exists. Fix
this by acquiring the lock earlier in FetchBlock.
The lock can be replaced with a net-specific lock when the remaining
CNodeState fields are moved to Peer.1 parent bcbf5ba commit 359680b
1 file changed
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1977 | 1977 | | |
1978 | 1978 | | |
1979 | 1979 | | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
1980 | 1986 | | |
1981 | 1987 | | |
1982 | 1988 | | |
1983 | 1989 | | |
1984 | 1990 | | |
1985 | 1991 | | |
1986 | 1992 | | |
1987 | | - | |
1988 | | - | |
1989 | 1993 | | |
1990 | 1994 | | |
1991 | 1995 | | |
| |||
0 commit comments