net: reset a peer's addrKnown under cs_addrKnown in the daily rebroadcast
SendMessages' 24-hour address rebroadcast cleared each peer's addrKnown under cs_vNodes only, while the message handler inserts into and tests the same filter under cs_addrKnown (AddAddressIfNotAlreadyKnown, IsAddressKnown): a data race on the bloom filter. Take cs_addrKnown for the reset, as CloseSocketDisconnect already does. The order is unchanged: cs_main (try-locked) -> cs_vNodes -> cs_addrKnown, as on the relay path. Exercised on regtest with two nodes on a mock clock moved 25 hours at a time: the reset ran 4 times (seen with a gdb breakpoint) with no fault. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+5
-2
@@ -8398,9 +8398,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
|
||||
LOCK(cs_vNodes);
|
||||
BOOST_FOREACH(CNode* pnode, vNodes)
|
||||
{
|
||||
// Periodically clear addrKnown to allow refresh broadcasts
|
||||
if (nLastRebroadcast)
|
||||
// Periodically clear addrKnown to allow refresh broadcasts. Under cs_addrKnown, as in
|
||||
// CloseSocketDisconnect: the message handler reads and inserts into it concurrently.
|
||||
if (nLastRebroadcast) {
|
||||
LOCK(pnode->cs_addrKnown);
|
||||
pnode->addrKnown.reset();
|
||||
}
|
||||
|
||||
// Rebroadcast our address
|
||||
AdvertizeLocal(pnode);
|
||||
|
||||
Reference in New Issue
Block a user