aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/pprof
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2016-01-06 00:25:24 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2016-01-06 05:51:38 +0000
commitc799e4a577e325d4ef3fd74ebd5415994096cd16 (patch)
tree8cf3ef16de54618dd8a6660a7f44cafe31e49b71 /src/net/http/pprof
parenta4f27c42254a3a79d71e7d6a1b8f45970621a644 (diff)
downloadgo-c799e4a577e325d4ef3fd74ebd5415994096cd16.tar.xz
net/http/pprof: stop profiling if client's connection closes
Fixes #13833 Change-Id: If0bd5f7dcfc39d34680d11eb998050f0900d5a26 Reviewed-on: https://go-review.googlesource.com/18283 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/pprof')
-rw-r--r--src/net/http/pprof/pprof.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/net/http/pprof/pprof.go b/src/net/http/pprof/pprof.go
index fd9154ac2a..63ff22123b 100644
--- a/src/net/http/pprof/pprof.go
+++ b/src/net/http/pprof/pprof.go
@@ -80,6 +80,17 @@ func Cmdline(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, strings.Join(os.Args, "\x00"))
}
+func sleep(w http.ResponseWriter, d time.Duration) {
+ var clientGone <-chan bool
+ if cn, ok := w.(http.CloseNotifier); ok {
+ clientGone = cn.CloseNotify()
+ }
+ select {
+ case <-time.After(d):
+ case <-clientGone:
+ }
+}
+
// Profile responds with the pprof-formatted cpu profile.
// The package initialization registers it as /debug/pprof/profile.
func Profile(w http.ResponseWriter, r *http.Request) {
@@ -100,7 +111,7 @@ func Profile(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Could not enable CPU profiling: %s\n", err)
return
}
- time.Sleep(time.Duration(sec) * time.Second)
+ sleep(w, time.Duration(sec)*time.Second)
pprof.StopCPUProfile()
}
@@ -124,7 +135,7 @@ func Trace(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Could not enable tracing: %s\n", err)
return
}
- time.Sleep(time.Duration(sec) * time.Second)
+ sleep(w, time.Duration(sec)*time.Second)
trace.Stop()
}