test: sock_tests: Handle partial reads in send_and_receive #36846

pull optout21 wants to merge 1 commits into bitcoin:master from optout21:2611-sock-tests-fix changing 1 files +8 −1
  1. optout21 commented at 11:20 AM on November 12, 2026: contributor

    The sock_tests/send_and_receive unit test can fail in the -- improbable -- case when network reads happen to arrive in smaller chunks.

    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.

    This test expects to read 4 bytes from the socket, and it expects that to happen in one Recv() call. However, there is no guarantee that data arrives in one call.

    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 #36751 .

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

    The fix is to replace the single Recv call with one or more repeated calls, until the expected amount of data is read, and do the checks only afterwards.

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

  2. test: sock_tests: Handle partial reads in send_and_receive
    In `sock_tests/send_and_receive`, replace a single `Recv` call with
    one or more repeated calls, until the expected amount of data is read,
    and do the checks only afterwards.
    There is no guarantee that the expected data is returned in one call,
    even if it is written in one `send()`, and even on a loopback
    connection, hence the need for the loop.
    baf2e9df91
  3. DrahtBot added the label Tests on Nov 12, 2026
  4. DrahtBot commented at 11:20 AM on November 12, 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-->


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

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