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

Open
optout21 wants to merge 2 commits from 2610-interface-http-test-fix into master AGit
optout21 commented 2026-11-02 12:10:29 +00:00 (Migrated from github.com)

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.

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.
DrahtBot commented 2026-11-02 12:10:39 +00:00 (Migrated from github.com)

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36729 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36729.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36729#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [Pranav-error](https://github.com/bitcoin/bitcoin/pull/36729#issuecomment-6949928370) | 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-->
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: 568d8f23edb2 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:965af1044d9e41839565702e4d9bd0a751eda81f6e8b6402747fa296ef84ebea:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:e310efb202bd1283bcdd25d5748078df1219c8ac --> <!-- ralph-head:568d8f23edb28368b140be1c6c0fee24b43252d7 --> <!-- ralph-case:07725ca8f3197c15d7cbc37ed9043dde4ed02c2d9a5da7c4cb03e22738bcaa6c --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`568d8f23edb2`](<https://git.fish.foo/bitcoin/bitcoin/commit/568d8f23edb28368b140be1c6c0fee24b43252d7>) · [Full review report](<https://review.fish.foo/traces/36729-568d8f23edb28368b140be1c6c0fee24b43252d7-1983-2.html>) · [Previous reports](<https://review.fish.foo/traces/36729/>) [permalink](<https://review.fish.foo/traces/36729-568d8f23edb28368b140be1c6c0fee24b43252d7-1983-2.html>)
optout21 commented 2026-11-02 13:32:57 +00:00 (Migrated from github.com)

Minor changes, applied DrahtBot suggestions (assert_greater_than_or_equal).

Minor changes, applied DrahtBot suggestions (`assert_greater_than_or_equal`).
optout21 commented 2026-11-13 10:13:32 +00:00 (Migrated from github.com)

Additional validation: The fix has been validated as well in a run with the reproducer, see https://github.com/bitcoin/bitcoin/pull/36724#issuecomment-6846132450
(current version 568d8f23ed)

Additional validation: The fix has been validated as well in a run with the reproducer, see https://github.com/bitcoin/bitcoin/pull/36724#issuecomment-6846132450 (current version 568d8f23edb28368b140be1c6c0fee24b43252d7)
hebasto commented 2026-11-13 18:33:15 +00:00 (Migrated from github.com)

cc @pinheadmz

cc @pinheadmz
Pranav-error commented 2026-11-17 13:49:03 +00:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36729
No description provided.