mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2910] [CLOSED] [Engine] serve: a request body that stops arriving is answered, not parked #4328
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#4328
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/2910
Author: @ctr-137
Created: 10/17/2026
Status: ❌ Closed
Base:
main← Head:serve-body-read-deadline📝 Commits (1)
ef62fbdserve: a request body that stops arriving is answered, not parked📊 Changes
2 files changed (+79 additions, -12 deletions)
View changed files
📝
serve/server.py(+35 -12)📝
serve/test_request_hardening.py(+44 -0)📄 Description
_body()is the one body read in the server with no deadline. A peer that announces a body and then says nothing — asilently dead client, no RST and no FIN — parks the handler thread and its fd for good, and the disconnect watcher
that would have noticed starts only after the body has been read.
The three body readers, and which one was the odd one out
The two others already bound their reads, in two different ways:
and
_drain_body(), which passesdeadline=time.monotonic() + DRAIN_SECONDSto_read_chunked()— a parameter_read_chunked()already had and_body()did not pass:What changed
BODY_STALL_S(STRATA_BODY_STALL_S, default 120 s,0= wait for ever as before), besidebody_limit(), shapedlike the engine's own read timeouts (#1317). Generous on purpose: this is a stopped client's deadline, not a
slow-client detector.
_body()sets it on the connection for the read and restores the previous timeout in afinally, exactly as_control_body()does, and answers a read that gets nothing with 408 — the status a body problem alreadycarries (
BadBody→self._json(e.status, ...)indo_POST).It is the wait for one read that gets nothing, not a bound on the whole body: a client that is sending, however
slowly, is never cut off, only one that has stopped. A half-read body leaves the stream unusable, so
close_connectionis set and the connection ends with the answer.Why the existing test file missed it
test_request_hardening.pycovers the two neighbours and stops just short of this one: the oversized case announces10 TiB, which the 413 refuses unread, and a half-close ends the read with a 400. A within-limit body that
announces a length and sends nothing is the case nothing constructed.
How this was checked
Three cases added to
serve/test_request_hardening.py: a within-limitContent-Lengthand a chunked body, eachannouncing a body and sending none, both must answer 408 — and the elapsed time is asserted too, or a client-side
timeout would pass the test as well. A complete body still answers 200, with the deadline set and with it off.
That file's 13 tests pass and
test_chunked_body.py's 12 pass unchanged, with no GPU and no engine (they runagainst
MockEngine).A three-arm probe against the real server — announce a body, send nothing, wait 8 s:
The two arms that reproduce the bug are the two with no deadline.
What I left alone
The response path is the same class and wants its own change: a streamed answer to a client that stops reading blocks
self.wfile.write()while the generator is suspended insidewith turn:, so the engine's single turn is held andevery later request waits (
serve/server.py:5976). Itsexcept OSErroralready does the right thing —cancel.set(),chunks.close()— andsocket.timeoutis anOSError, so only a send deadline is missing there.That is a separate pull request.
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.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.