Commit 915654e7 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

trace: tighten the check for duplicate registration

From comment at @santsai at https://github.com/golang/go/issues/24137#issuecomment-452983000

Change-Id: Icf0aff2172811752b240d94e709550b0da353360
Reviewed-on: https://go-review.googlesource.com/c/157378
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarJBD <jbd@google.com>
parent be1c187a
...@@ -86,6 +86,12 @@ import ( ...@@ -86,6 +86,12 @@ import (
// FOR DEBUGGING ONLY. This will slow down the program. // FOR DEBUGGING ONLY. This will slow down the program.
var DebugUseAfterFinish = false var DebugUseAfterFinish = false
// HTTP ServeMux paths.
const (
debugRequestsPath = "/debug/requests"
debugEventsPath = "/debug/events"
)
// AuthRequest determines whether a specific request is permitted to load the // AuthRequest determines whether a specific request is permitted to load the
// /debug/requests or /debug/events pages. // /debug/requests or /debug/events pages.
// //
...@@ -112,8 +118,8 @@ var AuthRequest = func(req *http.Request) (any, sensitive bool) { ...@@ -112,8 +118,8 @@ var AuthRequest = func(req *http.Request) (any, sensitive bool) {
} }
func init() { func init() {
_, pat := http.DefaultServeMux.Handler(&http.Request{URL: &url.URL{Path: "/debug/requests"}}) _, pat := http.DefaultServeMux.Handler(&http.Request{URL: &url.URL{Path: debugRequestsPath}})
if pat != "" { if pat == debugRequestsPath {
panic("/debug/requests is already registered. You may have two independent copies of " + panic("/debug/requests is already registered. You may have two independent copies of " +
"golang.org/x/net/trace in your binary, trying to maintain separate state. This may " + "golang.org/x/net/trace in your binary, trying to maintain separate state. This may " +
"involve a vendored copy of golang.org/x/net/trace.") "involve a vendored copy of golang.org/x/net/trace.")
...@@ -121,8 +127,8 @@ func init() { ...@@ -121,8 +127,8 @@ func init() {
// TODO(jbd): Serve Traces from /debug/traces in the future? // TODO(jbd): Serve Traces from /debug/traces in the future?
// There is no requirement for a request to be present to have traces. // There is no requirement for a request to be present to have traces.
http.HandleFunc("/debug/requests", Traces) http.HandleFunc(debugRequestsPath, Traces)
http.HandleFunc("/debug/events", Events) http.HandleFunc(debugEventsPath, Events)
} }
// NewContext returns a copy of the parent context // NewContext returns a copy of the parent context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment