Skip to content

Commit 39ca015

Browse files
committed
Merge bitcoin/bitcoin#33140: test: Avoid shutdown race in NetworkThread
fa6db79 test: Avoid shutdown race in NetworkThread (MarcoFalke) Pull request description: Locally, I am seeing rare intermittent exceptions in the network thread: ``` stderr: Exception in thread NetworkThread: Traceback (most recent call last): File "/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "./test/functional/test_framework/p2p.py", line 744, in run self.network_event_loop.run_forever() File "/python3.10/asyncio/base_events.py", line 603, in run_forever self._run_once() File "/python3.10/asyncio/base_events.py", line 1871, in _run_once event_list = self._selector.select(timeout) AttributeError: 'NoneType' object has no attribute 'select' ``` I can reproduce this intermittently via `while ./bld-cmake/test/functional/test_runner.py $(for i in {1..400}; do echo -n "tool_rpcauth "; done) -j 400 ; do true ; done`. I suspect this is a race where the shutdown starts the close of the network thread while it is starting. A different exception showing this race can be reproduced via: ```diff diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py index 610aa4c..64561e157c 100755 --- a/test/functional/test_framework/p2p.py +++ b/test/functional/test_framework/p2p.py @@ -741,6 +741,7 @@ class NetworkThread(threading.Thread): def run(self): """Start the network thread.""" + import time;time.sleep(.1) self.network_event_loop.run_forever() def close(self, *, timeout=10): ``` It is trivial to reproduce via any test (e.g. `./bld-cmake/test/functional/tool_rpcauth.py`) and shows a similar traceback to the one above: ``` Exception in thread NetworkThread: Traceback (most recent call last): File "/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "./test/functional/test_framework/p2p.py", line 745, in run self.network_event_loop.run_forever() File "/python3.10/asyncio/base_events.py", line 591, in run_forever self._check_closed() File "/python3.10/asyncio/base_events.py", line 515, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed ``` So fix the second runtime error in hope of fixing the first one as well. ACKs for top commit: brunoerg: code review ACK fa6db79 Tree-SHA512: ca352ebf7929456ea2bbfcfe4f726adcbfcfb3dc0edeaddae7f6926f998888f0bd8b987ddef60308266eeab6bffa7ebdc32f5908db9de5404df95635dae4a8f6
2 parents bcf794d + fa6db79 commit 39ca015

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def setup(self):
258258
self.log.debug('Setting up network thread')
259259
self.network_thread = NetworkThread()
260260
self.network_thread.start()
261+
self.wait_until(lambda: self.network_thread.network_event_loop.is_running())
261262

262263
if self.options.usecli:
263264
if not self.supports_cli:

0 commit comments

Comments
 (0)