test: Avoid shutdown race in NetworkThread
What changed, and why it matters
This is a one-line fix in Bitcoin Core's internal Python test framework. It adds a wait to ensure a background network thread has fully started before tests continue. The change only affects test code, not the live Bitcoin node software that users run, so it cannot be used to attack real Bitcoin wallets or the network. It addresses a timing-related test flakiness issue, not a security vulnerability in production code.
No security action required. Treat as a normal test reliability improvement. If backporting, include it only to reduce flaky CI failures.
Security signals we found
Race condition in thread startup (test-only)
Fix located exclusively in test framework code
Evidence from the diff
The patch modifies test/functional/test_framework/test_framework.py to call self.wait_until(lambda: self.network_thread.network_event_loop.is_running()) immediately after starting the NetworkThread. This prevents a race condition where subsequent test setup could proceed before the network event loop is actually running, which could cause intermittent test failures. The change is confined to the functional test harness and has no effect on bitcoind consensus, networking, or wallet code.
Changed components
test/functional/test_framework/test_framework.pyBitcoin functional test harness NetworkThread startupInspect captured patch +1 / −0
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 47339761..a44b3935 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -345,6 +345,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
self.log.debug('Setting up network thread')
self.network_thread = NetworkThread()
self.network_thread.start()
+ self.wait_until(lambda: self.network_thread.network_event_loop.is_running())
if self.options.usecli:
if not self.supports_cli:
Why this scored 16/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.