Repository navigation
Conversation
HttpRequest::send_request() sent 128-byte chunks with MSG_DONTWAIT and only checked for r < 0, so a short send silently dropped the rest of the chunk, and a full send buffer (EWOULDBLOCK) aborted the request. Send with a blocking socket and SO_SNDTIMEO, and loop until every byte of each chunk is written. A timeout or any send error fails the request, which the UCI HTTP target reports as 'not available'. Fixes GideonZ#1039 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add a loopback test (make test-send-all) with a peer that stalls before reading, so the send buffer fills: all 16 MiB must arrive in order. A reset connection and a peer that never reads must fail the request, the latter within the send timeout. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Closing in favour of #1043, which came first and also adds the receive timeout. In case it helps the review of #1043: we measured the bug on hardware with the UCI HTTP target POSTing a 196,608-byte body to a throttled server. Unfixed, the U64E delivered 66,195 bytes and the C64U 66,887, both ending in 503. With a blocking send loop like the one in both PRs, both devices delivered all 196,608 bytes in order, 3 of 3 runs each. We can run the same check on #1043 on a later bench flash if that is useful. Written with Claude Opus 5.5 in Claude Code. |
Collaborator
|
Thanks @JC-000 Much appreciated you also investigated this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1039.
Problem
HttpRequest::send_request()sent the request in 128-byte chunks withsend(..., MSG_DONTWAIT)and only checkedr < 0. In lwIP a non-blocking send that only partly fits returns the short positive count (lwip_send->netconn_write_partly, lwip26a22151f), so the rest of the chunk was silently dropped. If nothing fits it returns -1/EWOULDBLOCK, which aborted the request (the UCI HTTP target answers503 SERVICE UNAVAILABLE). Either way a request larger than the 16 KB send buffer, sent to a slow peer, was lost or truncated.Fix
Send on the blocking socket with
SO_SNDTIMEO(10 s;LWIP_SO_SNDTIMEOis already enabled) and loop until each chunk is fully written. The timeout applies to eachsend(), so a request fails after 10 s without progress; a slow peer that keeps accepting bytes keeps the UCI server task busy, as a slow upload does today. A send error or timeout returns -1, whichHttpTarget::cmd_exchangealready reports as 503.recv_responsehas no receive timeout; that is unchanged and out of scope. One function in one file.Tests
Host:
make -C target/pc/linux/test_http_target test-send-all(appended to the existing CI line). A loopback peer stalls before reading a 16 MiB request: all bytes must arrive in order; a reset connection and a peer that never reads (within the timeout) must fail the request. Master fails it (send_requestreturns -1 after 2.6 MB); the branch passes. Mutants that restoreMSG_DONTWAIT, ignore send errors, or drop the timeout are killed. The othertest_http_targettargets still pass (Ubuntu 24.04, ASan/UBSan).Hardware: the UCI HTTP target POSTs a 196,608-byte body to a throttled server (stalls 3 s, then drains) that counts the bytes; script and result files are on request. The RED images are bench builds carrying other unmerged work, whose
http_request.ccandhttp_target.ccare identical to master; the GREEN image has this fix plus the same other work.fdb59b059(no fix)218e36a52(fix), 3 runs1cd28abb1(no fix)218e36a52(fix), 3 runsHardware reproduced the
EWOULDBLOCKpath; the short-count path is covered by the loop and by lwIP's code, not observed on hardware.Written with Claude Sonnet 5.5 in Claude Code.