Repository navigation
Support ResponseController read and write deadlines on HTTP/2 streams - #39
Merged
Merged
Conversation
Owner
|
@pagpeter you can update the pr |
NewResponseController(w).SetReadDeadline and SetWriteDeadline returned ErrNotSupported for HTTP/2 requests, so a handler could not bound how long it waits on a single stream, for example on a CONNECT tunnel whose peer stops reading. Port the per-stream deadlines from golang.org/x/net/http2 a870f352 (CL 446256) and 93ec86b4 (CL 446335) to http2 and to the bundled server in h2_bundle.go. Server.ReadTimeout per stream and FlushError from those changes are not included. Without x/net efda1ce1, also not included, a write that hits its deadline fails with "http2: stream closed" rather than an error matching os.ErrDeadlineExceeded. A write deadline resets the stream. Releasing a write that is blocked on flow control needs the RST_STREAM scheduling fix, and canceling the handler's context needs closeStream to cancel it, so this builds on both. The tests run against both servers: a write blocked on flow control, read deadlines in the future and in the past, and a read deadline on a request without a body (golang.org/issue/58237). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pagpeter
force-pushed
the
http2-stream-deadlines
branch
from
October 26, 2026 16:30
2b24794 to
a8ade0b
Compare
pagpeter
marked this pull request as ready for review
October 26, 2026 16:32
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.
NewResponseController(w).SetReadDeadlineandSetWriteDeadlinereturnErrNotSupportedfor HTTP/2, so a handler cannot bound how long it waits on one stream (for example a CONNECT tunnel whose peer stops reading) without a connection deadline that affects every stream.This ports the per-stream deadlines from golang.org/x/net/http2 to
http2/server.goandh2_bundle.go: the read-deadline timer,onReadTimeoutand its stop on close from a870f352 (CL 446256), andSetReadDeadline,SetWriteDeadlineand their serve-loop case from 93ec86b4 (CL 446335), unchanged. Not included: the per-streamServer.ReadTimeoutandFlushError. Without x/net efda1ce1, a write that hits its deadline fails withhttp2: stream closed, not an error matchingos.ErrDeadlineExceeded.A write deadline resets the stream; that releases a write blocked on flow control thanks to #35, and cancels the handler's context thanks to #38.
Tests (
h2_server_frames_test.go, both servers): a write blocked on a zero flow-control window must fail after its deadline and cancel the handler's context; read deadlines in the future and in the past must release a read of a body that never comes; and a read deadline on a request without a body must not panic (golang.org/issue/58237). Each fails without the corresponding server's change.go test ./...passes.