test: Avoid shutdown race in NetworkThread #33140

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2508-test-less-racy changing 1 files +1 −0
  1. maflcko commented at 7:25 am on August 6, 2025: member

    Locally, I am seeing rare intermittent exceptions in the network thread:

     0stderr:
     1Exception in thread NetworkThread:
     2Traceback (most recent call last):
     3File "/python3.10/threading.py", line 1016, in _bootstrap_inner
     4self.run()
     5File "./test/functional/test_framework/p2p.py", line 744, in run
     6self.network_event_loop.run_forever()
     7File "/python3.10/asyncio/base_events.py", line 603, in run_forever
     8self._run_once()
     9File "/python3.10/asyncio/base_events.py", line 1871, in _run_once
    10event_list = self._selector.select(timeout)
    11AttributeError: '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:

     0diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py
     1index 610aa4ccca..64561e157c 100755
     2--- a/test/functional/test_framework/p2p.py
     3+++ b/test/functional/test_framework/p2p.py
     4@@ -741,6 +741,7 @@ class NetworkThread(threading.Thread):
     5 
     6     def run(self):
     7         """Start the network thread."""
     8+        import time;time.sleep(.1)
     9         self.network_event_loop.run_forever()
    10 
    11     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:

     0Exception in thread NetworkThread:
     1Traceback (most recent call last):
     2  File "/python3.10/threading.py", line 1016, in _bootstrap_inner
     3    self.run()
     4  File "./test/functional/test_framework/p2p.py", line 745, in run
     5    self.network_event_loop.run_forever()
     6  File "/python3.10/asyncio/base_events.py", line 591, in run_forever
     7    self._check_closed()
     8  File "/python3.10/asyncio/base_events.py", line 515, in _check_closed
     9    raise RuntimeError('Event loop is closed')
    10RuntimeError: Event loop is closed
    

    So fix the second runtime error in hope of fixing the first one as well.

  2. DrahtBot added the label Tests on Aug 6, 2025
  3. DrahtBot commented at 7:25 am on August 6, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33140.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  4. maflcko force-pushed on Sep 4, 2025
  5. test: Avoid shutdown race in NetworkThread fa6db79302
  6. maflcko force-pushed on Sep 29, 2025


maflcko DrahtBot

Labels
Tests


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-10-10 12:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me