Golang.org/x/net/trace Panic: http: multiple registrations for /debug/requests

Hi,

The problem is that one or more plugins that import the "golang.org/x/net/trace" package in a plugin type application (like Caddy) cause a panic:

panic: http: multiple registrations for /debug/requests

An issue has been logged inside the caddy-grpc project.

The reason is because both dns and grpc plugins use the Go gRPC package
which imports “golang.org/x/net/trace” in it’s trace.go file which in turn import the "golang.org/x/net/trace" package. The trace package has an init function that registers routes for the default http mux. This is where the panic occurs.

So when Caddy load and start both dns and grpc the panic occurs when the init() runs for a second time.

I’m not really sure what the resolution for a problem like this is. Can the handlers that’s specified in the trace package init() function be dynamically changed?

Pieter

My guess is that there is a vendored golang.org/x/net/trace somewhere in there. Otherwise init() would not be called twice.

Can the handlers that’s specified in the trace package init() function be dynamically changed?

No. A package’s init() is executed before any other package can interact with that package.

2 Likes
     	if mux.m[pattern].explicit {
     		panic("http: multiple registrations for " + pattern)
     	}

type ServeMux struct {
	mu    sync.RWMutex
	m     map[string]muxEntry
	hosts bool // whether any patterns contain hostnames
}

/go/src/net/http/server.go

ServeMux locked it, when twice and lock , no matter which request method type.

It is ok in fasthttp

Thanks @nathankerr

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.