mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2929] [CLOSED] [Engine] serve: the drain's deadline bounds the whole drain again, not just each chunk header #4344
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4344
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2929
Author: @ctr-137
Created: 10/17/2026
Status: ❌ Closed
Base:
main← Head:serve-drain-deadline📝 Commits (2)
9790a4aserve: the drain's deadline bounds the whole drain again, not just each chunk header921024dserve: the drain's deadline bounds a trickled chunk header, trailer and terminator too📊 Changes
2 files changed (+181 additions, -9 deletions)
View changed files
📝
serve/server.py(+70 -9)📝
serve/test_chunked_body.py(+111 -0)📄 Description
_drain_body's docstring says what the drain promises:The timeout was armed once per chunk, at the header, and the chunk was then read with
which waits for that whole buffer inside one call, looping over socket recvs internally. Each recv is bounded; the
call is not. A client that keeps a byte arriving inside the window — comfortably inside it — holds the drain
for ever: one MiB announced at one byte every 0.25 s is about three days, and the announced size is bounded only
by
body_limit()(256 MiB by default).The route only has to answer before reading the body for the drain to run at all, which
GET /nope(a 404) does.The change
The two things that make the bound real are the pair its sibling already uses, in
_drain_body's ownContent-Length loop:
armed()), so it is checked per socket read and not per chunk;read1, so one iteration is one socket read — the sibling's comment says it: "one socket read: read() wouldwait for it all".
I wrote the first of those two alone first, and it was not enough: the re-armed deadline still sat in front of a
read()that would not come back for days. The test added here is what showed it, and it is what would catch aregression of either half.
Scope: only the drain passes a deadline, and it reads with
keep=False, so every added branch is inert on thereal body path — a chunked body from
_body()and the control body both pass no deadline. The connection isHTTP/1.0 and ends with the answer either way, so ending the drain early can only ever drop a body that was going to
be dropped.
How this was checked
Two cases added to
serve/test_chunked_body.py.The trickle case: a 404 route that reads no body, 1 MiB announced, one byte every 0.25 s,
DRAIN_SECONDS1.0.Without the fix it fails — the client times out at 10.2 s because the drain never gives up — and with it the
connection is let go in 1.6 s.
The control: a complete 2 MiB chunked body is still read in full, and gets the answer that body deserves (a 400 about
the context, not about the framing). That is there because the re-arming must be inert when nothing rushed the
body.
No regressions:
python -m unittest discover -s serve→ 850 tests, 2 failures and 1 error, and all three fail onunmodified
mainas well:test_winjob— atasklistinvocation returnsNonein this environment;test_keepawake— waits on keep-awake callbacks withwait_for, fails alone onmain;test_responses— counts threads named(_loop)globally, fails alone onmain.Both of those last two are load- and order-dependent, which is why the same pair of files failed differently in
each arm across runs; each fails on
mainon its own.There is no issue for this; it came out of a static audit of the tree rather than a report. Happy to file one if you
would rather triage it there first.
Follow-up from review (midhatn)
The header/extension and trailer lines were still read with
readline(), and the two-byte chunk terminator withread(2)— one call may make several recvs, and the timeout armed before it bounds each recv, not the call. With a 200 ms deadline and a byte every 40 ms that was 750 ms (header) and 765 ms (trailer).read_line()/read_exact()now useread1and re-arm the deadline before every socket read when a deadline is set; with no deadline the originalreadline()/read()path is unchanged. Three regression tests cover a trickled header/extension, trailer and terminator.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.