Add assert that only one NetworkThread exists at any time in functional tests, and fix cases where that wasn't true.
fixes #11776
Seems like an easy mistake to make. Could you add a check to make it fail reliably?
Seems like an easy mistake to make. Could you add a check to make it fail reliably?
Excellent idea. I've repurposed this PR to add checking that only one NetworkThread is created. The extra checks have caught three additional potential bugs/races.
Add network thread_start(), network_thread_running() and
network_thread_join() utility functions in mininode.py and use
network_thread_running() in network thread assertions.
assumevalid.py, example_test.py and p2p-acceptblocks.py add
p2p_connections after the NetworkThread has been started. This isn't
permitted. Fix test to restart the network thread when adding new
connections.
p2p-leaktest.py had a potential race condition if the NetworkThread
hadn't terminated by the time we tried to restart it.
Check that P2PConnections aren't created after the NetworkThread
has started and that at any time only one NetworkThread is running.
423 | +def network_thread_start(): 424 | + """Start the network thread.""" 425 | + # Only one network thread may run at a time 426 | + assert not network_thread_running() 427 | + 428 | + NetworkThread().start()
Why not keep this instance and check for it, instead of enumerating threads with a custom name?
I can't see how that's any better. Perhaps you can push a branch to demonstrate what you mean.
rebased
Good idea. utACK 5c8ff26b2fc59d8bcfa2a8bfb7c9fe6d78cf6678