Merge bitcoin/bitcoin#36545: test: Fix intermittent issue in p2p_initial_headers_sync.py
What changed, and why it matters
This commit fixes a flaky automated test in Bitcoin Core. The test sometimes failed because it checked too quickly whether a network message had been sent. The fix makes the test wait until exactly one peer has received the expected message. There is no change to the actual Bitcoin node software that users run, so this has no security impact on real networks or wallets.
No security action required. This is a routine test reliability fix; review and merge as normal.
Security signals we found
No changes to consensus, networking, wallet, RPC, or cryptographic code
Change is confined to a functional test file
Fix addresses a test-level race condition, not a product-level vulnerability
Evidence from the diff
The commit modifies only test/functional/p2p_initial_headers_sync.py. It replaces an immediate, single-shot assertion that exactly one peer has received a getheaders message with a wait_until() helper that polls the peers’ last_message state until exactly one recipient is observed. This eliminates a race condition in the test harness where SendMessages() had not yet dispatched the getheaders when the assertion ran. The reproduction diff in the PR description (a temporary sleep in src/net_processing.cpp) was only used to trigger the race and is not part of the merged change.
Changed components
test/functional/p2p_initial_headers_sync.pyInspect captured patch +5 / −8
### test/functional/p2p_initial_headers_sync.py
@@ -56,15 +56,12 @@ def announce_random_block(self, peers):
p.send_and_ping(new_block_announcement)
def assert_single_getheaders_recipient(self, peers):
- count = 0
- receiving_peer = None
- for p in peers:
+ def getheaders_recipients():
with p2p_lock:
- if "getheaders" in p.last_message:
- count += 1
- receiving_peer = p
- assert_equal(count, 1)
- return receiving_peer
+ return [p for p in peers if "getheaders" in p.last_message]
+
+ self.wait_until(lambda: len(getheaders_recipients()) == 1)
+ return getheaders_recipients()[0]
def test_initial_headers_sync(self):
self.log.info("Test initial headers sync")Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.