Skip to content

Cancel the handler context when a stream is reset - #2

Closed
pagpeter wants to merge 1 commit into
masterfrom
http2-cancel-handler-ctx-on-reset
Closed

pagpeter wants to merge 1 commit into
masterfrom
http2-cancel-handler-ctx-on-reset

Conversation

@pagpeter

Copy link
Copy Markdown
Owner

When the server resets a stream because of a stream error (for example, a second HEADERS frame on a stream that has already ended), the handler's request context stays live. A handler waiting on r.Context().Done() never returns. Only an RST_STREAM from the client cancels it today.

This ports golang.org/x/net/http2 8aa6dbf4 (CL 585595, golang/go#67036): closeStream cancels the stream's context. It is one line in http2/server.go and the same line in h2_bundle.go.

Tests:

  • TestServerRequestCancelOnError in http2 is the x/net test.
  • TestBundledServerRequestCancelOnError does the same against the bundled server, using a small raw-frame client (h2_bundle_server_test.go).

Without the fix, the x/net test hangs and the bundled one fails after 5s; both pass with it. go test ./... passes; the new tests also pass with -race.

🤖 Generated with Claude Code

When the server reset a stream because of a stream error, the handler's
request context stayed live, so a handler waiting on it never returned.
Only a client RST_STREAM canceled it.

Port golang.org/x/net/http2 8aa6dbf4 (CL 585595, golang/go#67036) to
http2 and to the bundled server in h2_bundle.go: closeStream cancels the
stream's context.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant