[DONTMERGE] Test run with reproducer for forced chunked send #36724

pull optout21 wants to merge 8 commits into bitcoin:master from optout21:2610-net-send-chunks-reproducer changing 6 files +86 −27
  1. optout21 commented at 8:59 AM on November 2, 2026: contributor

    WARNING: NOT INTENDED FOR MERGING!

    Performing a test run with forced chunked send.

    All networking code using sockets must not make assumption about the chunking of the incoming/outgoing data, and should be resilient against any chunking. Normally, the chunking of the sends of the writer dictate the chunking of the receives at the reader, but this is not guaranteed by IP/TCP, intermediate networking elements may change the packet structure.

    This branch contains a stress test reproducer. For every socket send, sending is changed to break up data in small chunks. This forcedly changes chunking of the data stream. The goal is to test code for robustness in face of unexpected chunking of the data.

    This PR will be closed once the test runs complete, and kept for reference (some tests are expected to fail).

    WARNING: NOT INTENDED FOR MERGING!

  2. DrahtBot commented at 8:59 AM on November 2, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where comparison-specific test macros should replace generic comparisons:

    • test/functional/interface_http.py: assert res.index(b"HTTP/1.1 200") < res.index(b"HTTP/1.1 400") → Prefer assert_greater_than(res.index(b"HTTP/1.1 400"), res.index(b"HTTP/1.1 200")).

    <sup>2026-11-13 06:38:27</sup>

  3. DrahtBot added the label CI failed on Nov 2, 2026
  4. DrahtBot commented at 10:08 AM on November 2, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/41417100283/job/125183540072</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU required adding <thread> to src/util/sock.cpp, leaving a diff that the include-check rejects.</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  5. optout21 commented at 10:38 AM on November 2, 2026: contributor

    CI runs have completed, with some failures (that was expected). An issue has been raised to document the failed tests -- #36726 . Closing this PR (it was not intended for merging, keeping it for reference).

  6. optout21 closed this on Nov 2, 2026

  7. optout21 referenced this in commit 4d57e5dc88 on Nov 12, 2026
  8. optout21 commented at 11:41 AM on November 12, 2026: contributor

    New test run, with candidate test fixed on top of the reproducer. The branch now includes:

    Result: some failures:

    • p2p_v2_misbehaving.py: failed, due to similar reason as rpc_setban.py (new failure, failed in several runs)
    • iwyu failure, due to the reproducer commit
  9. optout21 reopened this on Nov 12, 2026

  10. DONTMERGE! net: Reproducer with forced chunked send
    A stress test reproducer. For every socket send, change sending to break up
    data in small chunks. This forecedly changes chunking of the data stream.
    The goal is to test code for robustness in face of unexpected chunking of the data.
    WARNING: Only for testing purposes, not to be merged!
    ab198d7d9c
  11. test: interface_http: assert array length before accessing elements ec9ce18cbe
  12. test: interface_http: Fix for case when a response doesn't arrive in one recv
    Several checks read a response with one recv() call (recv_raw(), up to
    1024 bytes) and assumed it held the whole HTTP response. TCP does not
    guarantee this: on a slow or loaded machine a response can arrive split
    across several reads, so the check sees only the status line or headers
    and fails.
    
    The loops in check_pipelining and check_slow_read_throttle had a related
    problem. They counted "HTTP/1.1 200" markers in each read separately, so
    a marker split across two reads was never counted, and the loop waited
    until the socket timed out.
    
    Add BitcoinHTTPConnection.recv_responses(count), which keeps reading
    until `count` complete responses (headers plus Content-Length body) have
    arrived, or the server closes the connection. Use it everywhere a full
    response is expected, and replace the counting loops with explicit
    assertions on the result.
    
    recv_raw() is kept for the timeout checks, where a single blocking read
    is the intended behaviour.
    9f7ae464aa
  13. DONTMERGE! Ignore functest rpc_setban.py --v2transport
    This is a temporary ignore for a test run for test fixes
    with a forced send reproducer, in PR ##36724
    WARNING: Only for testing purposes, not to be merged!
    9990c84be3
  14. optout21 force-pushed on Nov 12, 2026
  15. optout21 commented at 4:43 PM on November 12, 2026: contributor

    New test run, with candidate test fixed on top of the reproducer. The branch (04af8973955b5a4080aceaa0bb5febe2a0306e55) now includes:

    • Force send reproducer -- ab198d7d9c36b59b0370a8cf3d39980795ee06b9
    • interface_http.py fix -- f89bd7f5a5843e84ae66be2bde791f0a2ae5dd41 and 568d8f23edb28368b140be1c6c0fee24b43252d7 from #36729
    • ignore rpc_setban.py --v2transport -- ba709b5db5491ff03a5f6a89b8cc34b56397f4d0 from https://github.com/optout21/bitcoin/tree/2611-dontmerge-ignore-setban-ftest
    • Fix for p2p_v2_encrypted.py & p2p_v2_misbehaving.py -- be35cbb0b16d97e82f5634e76314e87b430a9360 and be88a3b926bd18d2243ca1a2e21332bca4f5d7e1 from #36730

    Results: previous errors resolved (p2p_v2_misbehaving.py and IWYU), failures:

    • New failure in p2p_handshake.py --v2transport
    • test ancestor commits failed, this is due to inconsistent intermediary state, normal.
  16. test: p2p: check v1 magic bytes only after the full header
    The v1 message parser in P2PConnection rejected the stream as soon as
    the first 4 bytes did not match the network magic. bitcoind's
    V1Transport::readHeader waits for the full 24-byte header before
    checking the magic.
    
    The v2 to v1 downgrade relies on bitcoind's behaviour: an outbound v2
    connection is only retried with v1 (V2Transport::ShouldReconnectV1)
    if at least a v1 header's worth of bytes had been sent before the
    peer disconnected. If the node's first send reaches the test peer in
    small pieces, the Python peer could disconnect after just 4 bytes, the
    node would not retry with v1, and p2p_v2_encrypted.py would time out
    waiting for the reconnection.
    
    Match bitcoind by checking the magic only once the full header has
    been received.
    dae15ce56c
  17. test: p2p: Don't use empty garbage as "not yet responded" in v2 responder
    When P2PConnection is the v2 responder, _on_data_v2_handshake() used
    `not self.v2_state.sent_garbage` to decide whether it still had to send
    its ellswift key. The garbage length is random in [0, MAX_GARBAGE_LEN],
    so in about 1 in 4096 connections it is empty and the check stays true
    after the key has been sent.
    
    If the peer's 64-byte key then arrives in more than one piece,
    complete_handshake() asks for more data, and on the next read the
    responder runs respond_v2_handshake() again: it generates and sends a
    second key, and misaligns the received key bytes. Both sides then wait
    for a garbage terminator that never comes. With the test default
    peertimeout=999999999 nobody times out, and the test can hang until its
    own timeout.
    
    Check whether our ellswift key has been generated instead.
    45bae4f193
  18. test: p2p_v2_misbehaving: Handle partial ellswift read
    The node's 64-byte ellswift key can arrive in several chunks. In that
    case EncryptedP2PState.complete_handshake() returns (0, b"") to signal
    that more data is needed. The WrongGarbageTerminatorState override
    bit-flipped the returned bytes unconditionally, which crashed in
    random_bitflip() on empty input and dropped the connection.
    
    Return the "need more data" result unchanged before tampering with it.
    e73a65e7aa
  19. test: v2_p2p: Return bytes consumed per call in respond_v2_handshake
    respond_v2_handshake() returned len(self.received_prefix) as the number
    of bytes consumed, and the caller trims recvbuf by that amount. But
    received_prefix accumulates across calls, so when the v1 prefix check
    spans more than one read, too many bytes are dropped from recvbuf.
    
    This happens when the peer's ellswift key starts with bytes that match
    the v1 prefix (e.g. the first network magic byte, about 1 in 256 keys)
    and a read ends inside that matching part. The remaining key bytes are
    then misaligned, the shared secret is wrong, and the handshake stalls.
    
    Return only the number of bytes consumed in the current call.
    b45fa0069d
  20. optout21 force-pushed on Nov 13, 2026
  21. optout21 commented at 6:39 AM on November 13, 2026: contributor

    New test run, with candidate test fixed on top of the reproducer.

    The branch now (b45fa0069d5c2f81965c9c0b178f1500c1ec8db3) includes:

    • Force send reproducer -- ab198d7d9c36b59b0370a8cf3d39980795ee06b9
    • interface_http.py fix -- f89bd7f5a5843e84ae66be2bde791f0a2ae5dd41 and 568d8f23edb28368b140be1c6c0fee24b43252d7 from #36729
    • ignore rpc_setban.py --v2transport -- ba709b5db5491ff03a5f6a89b8cc34b56397f4d0 from https://github.com/optout21/bitcoin/tree/2611-dontmerge-ignore-setban-ftest
    • p2p_v2_encrypted.py & p2p_v2_misbehaving.py fixes -- 4 commits from #36730 (be35cbb, be788a9, baafaf8, ba7dde0)

    Result: all tests passed, except "test ancestor commit" (as expected, due to the fact that incomplete-commit states fail due to the reproducer).

  22. optout21 closed this on Nov 13, 2026

  23. optout21 reopened this on Nov 13, 2026

  24. optout21 closed this on Nov 13, 2026

  25. optout21 reopened this on Nov 13, 2026

  26. optout21 commented at 10:15 AM on November 13, 2026: contributor

    Closing.

  27. optout21 closed this on Nov 13, 2026


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-11-24 06:51 UTC

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