Skip to content

x/net/http2: cancel stream context more proactively when closing or resetting stream #68099

Description

@dagood

Go version

go version go1.22.4 linux/amd64

Output of go env in your module/workspace:

GOARCH='amd64'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
[... trimmed, does not seem relevant]

What did you do?

When the server closes or resets a stream, in some cases my handler is still running. The handler may be performing an expensive operation or using a lot of memory. Canceling the context as soon as possible means the handler can detect that it's no longer doing useful work and stop wasting resources.

What did you see happen?

In some cases, the handler context is not canceled until later than I'd expect. For example, the scheduler might do a lot of work to wrap up http2 state for a stream reset before cancelling the context.

What did you expect to see?

As soon as the server knows that continuing to run the handler won't do any useful work, the context should be cancelled.

I wrote a CL to cancel earlier in a few cases, but I had trouble writing tests for it: https://go-review.googlesource.com/c/net/+/536515. I'm filing this as an issue in case someone more familiar with x/net/http2 wants to work on it. 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions