panic: http: multiple registrations for /debug/requests
Asked Answered
B

2

10

I vendored two projects in my go project. And I successfully compiled my project. When I ran my project, it reported error "panic: http: multiple registrations for /debug/requests". The detailed errors is shown below.

goroutine 1 [running]:
net/http.(*ServeMux).Handle(0x19ae000, 0x126bb20, 0xf, 0x1964540, 0x1297d90)
/usr/local/go/src/net/http/server.go:2270 +0x627
net/http.(*ServeMux).HandleFunc(0x19ae000, 0x126bb20, 0xf, 0x1297d90)
/usr/local/go/src/net/http/server.go:2302 +0x55
net/http.HandleFunc(0x126bb20, 0xf, 0x1297d90)
/usr/local/go/src/net/http/server.go:2314 +0x4b
github.own.com/chalex/testfabric/vendor/github.com/hyperledger/fabric-sdk-go/vendor/golang.org/x/net/trace.init.0()
/home/chalex/ibm/src/github.own.com/chalex/testfabric/vendor/github.com/hyperledger/fabric-sdk-go/vendor/golang.org/x/net/trace/trace.go:115 +0x42
github.own.com/chalex/testfabric/vendor/github.com/hyperledger/fabric-sdk-go/vendor/golang.org/x/net/trace.init()
<autogenerated>:1 +0x1cd
github.own.com/chalex/testfabric/vendor/github.com/hyperledger/fabric-sdk-go/vendor/google.golang.org/grpc.init()
<autogenerated>:1 +0x82
github.own.com/chalex/testfabric/vendor/github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer.init()
<autogenerated>:1 +0x6f
github.own.com/chalex/testfabric/vendor/github.com/hyperledger/fabric-sdk-go/api/apitxn.init()
<autogenerated>:1 +0x44
github.own.com/chalex/testfabric/chaincode/client.init()
<autogenerated>:1 +0x49
main.init()

Does anyone have any idea on how to fix it? I guess it's because the two projects I imported both listen on /debug/requests?

Brazilein answered 22/12, 2017 at 8:14 Comment(3)
Your guess i right. Must change code.Hildegard
This is why it's dangerous for libraries to do this sort of thing in init functions. They should only register handlers when you explicitly tell them to.Anthrax
Thank you. @Hildegard @Adrian. I found the reason. It's because of the golang.org/x/net/trace project. In it's init() function, they handle the debug/request with hard code. So if two projects both import that library, then there is a conflict.Brazilein
B
9

I found the reason. It's because of the golang.org/x/net/trace project. In it's init() function, they handle the debug/request with hard code. So if two projects both import that library, then there is a conflict.

Brazilein answered 25/12, 2017 at 12:58 Comment(1)
The cause of issue is as explained by @chalex above. The temporary fix for me was to comment out the init() method inside the $GOPATH/pkg/mod/<mypackage>/Godeps/_/x/net/trace/trace.goBerkeleianism
P
5

More than one project used golang.org/x/net/trace, and some project saved golang.org/x/net/trace in its vendor directory, so that is causing the conflict. Fix the conflict by deleting others and only leaving one,then the problem will be solved.

Pigeonhole answered 25/5, 2018 at 3:1 Comment(1)
Does anyone know a way to figure out WHAT package is responsible for the "double" vendoring?Gujarat

© 2022 - 2024 — McMap. All rights reserved.