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

pull sdaftuar wants to merge 4 commits into bitcoin:master from sdaftuar:p2p-fix-invalidblockrequest changing 3 files +91 −70
  1. sdaftuar commented at 7:55 PM on May 1, 2015: member

    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.

  2. Fix mininode disconnections to work with select ef3281750d
  3. Don't run invalidblockrequest.py in travis until race condition is fixed 5487975ca3
  4. Fix potential race conditions in p2p testing framework
    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.
    574db4816f
  5. Fix comptool send_message call when MAX_INV_SZ reached 2a22d4be9b
  6. jonasschnelli commented at 1:34 PM on May 2, 2015: contributor

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

  7. laanwj added the label Tests on May 4, 2015
  8. laanwj merged this on May 4, 2015
  9. laanwj closed this on May 4, 2015

  10. laanwj referenced this in commit 82d06e2338 on May 4, 2015
  11. DrahtBot locked this on Sep 8, 2021

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: 2026-04-14 12:16 UTC

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