mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2916] [CLOSED] [Engine] serve: the handler's connection has a deadline, so a peer that has stopped cannot own the server #4334
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#4334
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/2916
Author: @ctr-137
Created: 10/17/2026
Status: ❌ Closed
Base:
main← Head:serve-connection-deadline📝 Commits (1)
fee949eserve: the handler's connection has a deadline, so a peer that has stopped cannot own the server📊 Changes
2 files changed (+144 additions, -0 deletions)
View changed files
📝
serve/server.py(+12 -0)➕
serve/test_connection_deadline.py(+132 -0)📄 Description
A client that has stopped — a silently dead one (no RST, no FIN), or one still connected that never reads its
streamed answer — can own a handler thread for good and, worse, the engine's single turn. This gives the
handler's connection a deadline, and everything else that was needed was already written.
What happens now
The SSE loop writes with
self.wfile.write()while the generator is suspended inside theExitStackthat holds thefifo (
Service.request), so every later request queues behind a stream nobody is reading:The disconnect watcher (#430 #431) cannot see this. It polls the socket for readability and treats EOF as a
hang-up, which catches a client that closed; a client that is connected and simply not reading is not readable, and
the watcher never closes or shuts down the socket, so it cannot release a write that is already blocked.
The change
socketserver.StreamRequestHandler.setup()doesif self.timeout is not None: self.connection.settimeout(...), sothis is the deadline for every socket operation the handler makes — the request line, the body, and the writes.
That covers three sites of one class at once, including one the audit did not have: a client that connects and sends
nothing at all, not even a request line, parked a thread just as well.
Nothing else had to be written, because the recovery already exists in two places:
except OSErrornotes the outcome, callscancel.set()andchunks.close()— and closing thegenerator unwinds
with turn:, which releases the turn;BaseHTTPRequestHandler.handle_one_requestcatchesTimeoutErroraround the wholedo_<method>()call —"a read or a write timed out. Discard this connection" — as a backstop for anything that escapes the above.
It fires only when nothing has moved in either direction for that long, so a client that is sending or reading,
however slowly, is never cut off.
0switches it off (wait for ever, as before).How this was checked
Measured against the real server, as shipped versus with a 2 s deadline:
serve/test_connection_deadline.py(new, 4 tests) makes both of those regressions permanent: a silent client'sconnection is ended at the deadline; a stream nobody reads no longer holds the turn; a reader slower than the
writer still receives the whole stream; and
0switches it off. All four need no GPU and no engine.With the
timeoutattribute removed and everything else left in place, two of the four fail — the silent clientand the held turn — and the other two pass. That is the pair of defects exactly.
No regressions:
python -m unittest discover -s serve→ 852 tests, one error, intest_winjob.py, which failsthe same way on unmodified
main(atasklistinvocation returningNoneon this machine).What I left alone
Nothing about the body read.
serve/test_request_hardening.py's case (#2814, pull #2910) gives the body its owndeadline and answers 408, because a body that stops arriving deserves an answer rather than a discarded connection.
With this in place that one is belt-and-braces: if you would rather have a single knob,
BODY_STALL_Scan fold intoPEER_STALL_S.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.