test: interface_http: Fix for case when a response doesn't arrive in one recv #36729

pull optout21 wants to merge 2 commits into bitcoin:master from optout21:2610-interface-http-test-fix changing 1 files +46 −17
  1. optout21 commented at 12:10 PM on November 2, 2026: contributor

    The interface_http.py test can fail in the -- improbable -- case when network reads happen to arrive in smaller chunks (when reading HTTP response from the socket).

    Related to #36726 .

    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. In test using sockets on the same host, this is not very likely, but still possible.

    This tests reads complete HTTP responses, by checking for the HTTP response code texts ("HTTP/1.1 200"). In doing so, it implicitly assumes that one HTTP response arrives in one recv(). There is no guarantee for this.

    This was found -- and can be reproduced -- by using a reproducer patch, that forces all socket sends to use smaller chunking. For the run with the reproducer see #36724 .

    The issue is test-code only, the non-test code is correct.

    The fix is to follow standard HTTP parsing: read the header until the new line, extract the content length from the header, and read the body of that size. Use repeated receives if needed, until the full response is read.

    This fix makes the test more robust, even though a failure due to this issue in CI is very unlikely, but not impossible.

  2. DrahtBot added the label Tests on Nov 2, 2026
  3. DrahtBot commented at 12:10 PM 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.

    Type Reviewers
    ACK Pranav-error

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. optout21 marked this as ready for review on Nov 2, 2026
  5. test: interface_http: assert array length before accessing elements f89bd7f5a5
  6. 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.
    568d8f23ed
  7. optout21 force-pushed on Nov 2, 2026
  8. optout21 commented at 1:32 PM on November 2, 2026: contributor

    Minor changes, applied DrahtBot suggestions (assert_greater_than_or_equal).

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

    Additional validation: The fix has been validated as well in a run with the reproducer, see #36724 (comment) (current version 568d8f23edb28368b140be1c6c0fee24b43252d7)

  10. hebasto commented at 6:33 PM on November 13, 2026: member
  11. Pranav-error commented at 1:49 PM on November 17, 2026: none

    tACK 568d8f23e

    Fixes the pipelining failure reproduced under forced chunking, which fails deterministically on master.

    The drain-loop change is necessary; reverting it brings back the timeout. The missing Content-Length fallback is safe since bitcoind always sends it for HTTP/1.1 responses with a body (httpserver.cpp:574–583).

    Verified with the reproducer and a normal build. No regressions.


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