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?

Patryk
  • 22,602
  • 44
  • 128
  • 244
Chalex
  • 321
  • 2
  • 9
  • 3
    Your guess i right. Must change code. – Volker Dec 22 '17 at 08:23
  • 1
    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. – Adrian Dec 22 '17 at 14:06
  • Thank you. @Volker @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. – Chalex Dec 23 '17 at 14:48

2 Answers2

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.

Chalex
  • 321
  • 2
  • 9
  • 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//Godeps/_/x/net/trace/trace.go``` – anisbhsl Jul 15 '20 at 07:37
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.

Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60
Bruce
  • 1,718
  • 20
  • 15