做项目时使用了Grpc与登陆服务器进行通信,ETCD用来服务的发现。结果刚运行直接崩溃,百思不得其解。经过GOOGLE发现问题所在:https://stackoverflow.com/questions/47938005/panic-http-multiple-registrations-for-debug-requests
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.
more than one project used golang.org/x/net/trace
, and some project saved golang.org/x/net/trace
in it's vendor
, so that cause the conflict, fix the conflict(delete others only leave one
),then the problem will be solved.
说是两个项目同时使用golang.org/x/net/trace 然后初始化两次导致失败,说是只能一个使用才能解决。
两个都需要怎么可能只能一个使用,于是上google一下,结果发现有许多人出现这个问题。
https://github.com/grpc/grpc-go/issues/566
在grpc上面提到这个问题。
问题:
The root cause of the error seems to be the module golang.org/x/net/trace
. Its init() registers a handler to the same URL (e.g. /debug/requesets). Therefore importing the module more than twice causes the above panic.
I'm not sure here is a suitable place for reporting the problem. I'd like to hear gRPC developers' opinion. Should I go to the issue tracker of golang? Or is a workaround for this problem known?
解决方案:
@immesys This is a dependency management problem, not something that we can solve within gRPC.
Please look into the dependency management tool you use to see how to avoid double import.
The discussions in etcd repo (coreos/etcd#9155, coreos/etcd#9240) might help.
大致意思就是这个时GO包管理的问题。。
找到问题就很好解决了,直接百度 go依赖管理-govendor
go get -u github.com/kardianos/govendor
先获取这个,然后将govendor.exe放入path中
进入项目中,govendor init初始化一下,程序会自动生成一个vendor目录
最重要的一步来了 govendor add +external
使用这个会把你所需要的包全部放入刚才的vendor目录中
这个时候你go build 运行程序就不会发生panic了!!
有时候还是需要Google一下。。。。