Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python P2P testing bugfixes: rework locking to eliminate race conditions and fix comptool.py #6094

Merged
merged 4 commits into from May 4, 2015

Conversation

sdaftuar
Copy link
Member

@sdaftuar sdaftuar commented May 1, 2015

This builds off of #6089, with more fixes for the python p2p testing framework (see #5981).

Previously, each NodeConnCB had its own lock to synchronize data structures used by the testing thread and the networking thread, and NodeConn provided a separate additional lock for synchronizing access to each send buffer. However, there was no existing lock to protect other data structures that are not specific to a single NodeConnCB, such as BlockStore or TxStore, which are created in comptool.py and shared by all the NodeConnCB instances.

Moreover comptool.py had a race condition because it wasn't synchronizing access to the BlockStore, nor using the existing NodeConnCB locks before accessing the block_request_map inside the comptool.py TestNode objects. I believe this type of race condition triggered a test failure reported in #5981.

This pull tries to simplify the synchronization and make the code more robust to race conditions by replacing all the individual locks one single global lock that we now use to synchronize the two threads. The networking thread acquires this lock before delivering every message; NodeConn.send_message() uses this lock to synchronize access to the sendbuf; and the thread running the test logic will now acquire this lock before accessing any data shared with one or more NodeConnCB or NodeConn objects.

Previously, each NodeConnCB had its own lock to synchronize data structures
used by the testing thread and the networking thread, and NodeConn provided a
separate additional lock for synchronizing access to each send buffer.  This
commit replaces those locks with a single global lock (mininode_lock) that we
use to synchronize access to all data structures shared by the two threads.

Updates comptool and maxblocksinflight to use the new synchronization
semantics, eliminating previous race conditions within comptool, and re-enables
invalidblockrequest.py in travis.
@jonasschnelli
Copy link
Contributor

Tested ACK.
Did run bipdersig-p2p.py, invalidateblock.py, maxblocksinflight.py multiple times and there where no more race-conditions.

@laanwj laanwj added the Tests label May 4, 2015
@laanwj laanwj merged commit 2a22d4b into bitcoin:master May 4, 2015
laanwj added a commit that referenced this pull request May 4, 2015
2a22d4b Fix comptool send_message call when MAX_INV_SZ reached (Suhas Daftuar)
574db48 Fix potential race conditions in p2p testing framework (Suhas Daftuar)
5487975 Don't run invalidblockrequest.py in travis until race condition is fixed (Suhas Daftuar)
ef32817 Fix mininode disconnections to work with select (Suhas Daftuar)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants