Go 使用Grpc 与 ETCD clientV3 出现 panic: http: multiple registrations for /debug/requests

  做项目时使用了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#9155coreos/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一下。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值