Skip to content

net/http/pprof: respect timeouts set using http.ResponseController #62358

Closed
@komuw

Description

@komuw

Example program with issue: https://go.dev/play/p/DoZD1wMDPhw

Most time I find myself wanting to run my http requests with tight deadlines using http.Server.WriteTimeout.
While at the same time, I would like requests to the pprof endpoints to operate under more lenient timeouts.
For example I would set http.Server.WriteTimeout to 3 seconds and at the same time want to be able to take a pprof sample that would take a long time curl -vkL "http://localhost:9192/debug/pprof/profile?seconds=30"

I thought I would use http.NewResponseController to do that, see https://go.dev/play/p/DoZD1wMDPhw
However, that fails with profile duration exceeds server's WriteTimeout.
This is because the pprof handlers only consider the server timeout;

func durationExceedsWriteTimeout(r *http.Request, seconds float64) bool {
srv, ok := r.Context().Value(http.ServerContextKey).(*http.Server)
return ok && srv.WriteTimeout != 0 && seconds >= srv.WriteTimeout.Seconds()
}

My proposal is that they should also consider any timeout that has been set by http.ResponseController.
I don't know how such a functionality might be implemented since durationExceedsWriteTimeout takes a http.Request and its context does not contain information on whether http.ResponseController has been used.

The current workaround is to use two servers, one for application handler and one for pprof handlers each with its own http.Server.WriteTimeout. But I like having one server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions