test: Potential test errors, due to assumptions on socket data chunking (interface_http, ...) #36726

issue optout21 opened this issue on November 2, 2026
  1. optout21 commented at 10:36 AM on November 2, 2026: contributor

    Summary: A test run with a forced reproducer, with changed socket data send chunking discovered issues with a few tests.

    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.

    A test run was executed with a stress test reproducer. For every socket send, sending was changed to break up data in small chunks. This forcedly changed chunking of the data stream. This way code was tested for robustness in face of unexpected chunking of the data. The run is here: #36724 , the reproducer can be seen here .

    A few test failed, which where analyzed.

    On the positive note, NO NON-TEST ISSUES were identified.

    The list of failed tests with the failure root cause:

    Failed tests:

    1. interface_http.py -- Failed in several CI runs. A wrong assumption in the test; it is implicitly assumed that an HTTP response arrives in a single recv. Being fixed, #36729 .

    2. rpc_setban.py --v2transport Failed in two CI runs (1 2). The reason is more subtle, the tested use case can have two outcomes, depending on weather a full key (64 bytes) could be sent on a closing connection or not (ShouldReconnectV1()). The second case is very unlikely, but still can happen. The test is only prepared for the first outcome, with the reproduces the second can happen, causing it to fail. Up for discussion whether should be fixed or kept as-is.

    3. p2p_v2_encrypted.py -- Failed once, a time-out occurred (on Windows). Also related to v1/v2 transport selection (ShouldReconnectV1()), but the reason is in the test framework (p2p.py, 358-361). The Python v1 peer disconnects after reading 4 bytes. If they are sent in separate syscalls, the sender node will not be able to send all 64 key bytes. This will cause ShouldReconnectV1() to return false, and the node will not reconnect. The test waits on reconnect. A potential fix is to change Python v1 parser to behave like bitcoind by moving the magic check after the full-header length check. Fix is attempted in #36730 .

    A note regarding chance of occurrence. When a test makes an assumption about data chunking (1.), it can pass reliably in CI runs and local tests. However, this is still a latent bug, as there is no guarantee for correct execution. Data chunking can change between sender and receiver. So the fix is recommended, to make the test more resilient, but the issue is low priority.

  2. maflcko added the label Tests on Nov 2, 2026
  3. maflcko added the label CI failed on Nov 2, 2026
  4. optout21 commented at 12:12 PM on November 2, 2026: contributor

    PR #36729 raised to fix interface_http.

  5. optout21 commented at 12:43 PM on November 2, 2026: contributor

    PR #36730 raised to fix p2p_v2_encrypted.py, with a small change to the test framework p2p v1 peer.

  6. optout21 commented at 11:23 AM on November 5, 2026: contributor

    A similar reproducer run was executed, with receiver-side forced chunking of data: #36751 .

    Test failures identified there, with some CI runs where they failed, are:

    • sock_tests/send_and_receive unit test. A unit test failure prevented execution of the integration tests, so a fix was included in the reproducer PR as well. It still fails in the per-commit checks log.

    • interface_http.py Failed many times. Three logs are included here: 1 2 3.

    • feature_torcontrol.py Failed in two windows tests (1 2)

  7. Pranav-error commented at 3:19 PM on November 12, 2026: none

    While going through the socket-chunking cases here, I noticed another spot that assumes a recv()-boundary-independent marker count, in a method not covered by #36729: the response-drain loop at the end of check_slow_read_throttle in test/functional/interface_http.py:

    num_res = 0
    while num_res < count + 2:
        response = conn.conn.sock.recv(10 * 1024 * 1024)
        num_res += response.count(b"HTTP/1.1 200")
    

    response.count(b"HTTP/1.1 200") is evaluated on each individual recv() chunk. If a recv() boundary splits the HTTP/1.1 200 marker across two chunks (e.g. one ends ...HTTP/1., the next starts 1 200...), it is counted in neither, so num_res undercounts and the loop can't reach count + 2, blocking until the socket timeout. A ~10 MB drain is quite likely to span multiple recv() calls, so this looks like the same latent class.

    Counting over the accumulated buffer avoids the split-marker case:

    buf = bytearray()
    num_res = 0
    while num_res < count + 2:
        data = conn.conn.sock.recv(10 * 1024 * 1024)
        if not data:
            break
        buf += data
        num_res = buf.count(b"HTTP/1.1 200")
    

    Found by inspection; I haven't run it under the forced-chunking reproducer. Happy to open a PR if it's useful and not already covered elsewhere.

  8. optout21 commented at 4:46 PM on November 12, 2026: contributor

    Thanks, I will check. It can be included in #36729, if you agree.

  9. Pranav-error commented at 7:12 PM on November 12, 2026: none

    Sounds good, please include it in #36729.

    The minimal change is to accumulate into a buffer and count over everything received so far, so a marker split across a recv() boundary is still counted once both halves arrive:

    buf = bytearray()
    num_res = 0
    while num_res < count + 2:
        data = conn.conn.sock.recv(10 * 1024 * 1024)
        if not data:
            break
        buf += data
        num_res = buf.count(b"HTTP/1.1 200")
    

    Happy to open a separate PR instead if you'd rather keep #36729 focused — whichever is easier for you.

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

    While going through the socket-chunking cases here, I noticed another spot that assumes a recv()-boundary-independent marker count, in a method not covered by #36729:

    Thanks for looking into this. I looked at it now, and as I see, a fix has been already applied. You're right that the original drain loop had the same problem: counting HTTP/1.1 200 in each recv() chunk misses a marker that's split across two chunks. It also spun forever on EOF, since recv() keeps returning b"".

    The fix is already in the PR (and has been with its first version). The last hunk of 568d8f23ed replaces that loop with recv_responses(count + 2). That helper collects into one buffer and frames each response by Content-Length, so it doesn't depend on where recv() splits the data, and it stops when the connection closes. The HTTP/1.1 200 count is then taken over the whole buffer and checked with assert_greater_than_or_equal(num_res, count + 2). So no separate PR is needed, but please do re-check if you wish.

  11. Pranav-error commented at 3:34 AM on November 20, 2026: none

    Thank you @optout21!


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