sofastack / sofa-rpc

SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework.
https://www.sofastack.tech/sofa-rpc/docs/Home
Apache License 2.0
3.81k stars 1.17k forks source link

Consul registry uses the rest protocol exception #726

Closed leyou240 closed 4 years ago

leyou240 commented 4 years ago

Describe the bug

A clear and concise description of what the bug is. 使用 @ScienJus 提供的demo 增加使用rest协议。服务无法正常解除注册,并且启动后在日志中有异常

@SofaService(
        bindings = {
                @SofaServiceBinding(
                        bindingType = "bolt"
                        , parameters = @SofaParameter(key = ConsulConstants.CONSUL_SERVICE_NAME_KEY, value = "${spring.application.name}-hello-service")
                ),
                @SofaServiceBinding(
                        bindingType = "rest",
                        parameters = @SofaParameter(key = ConsulConstants.CONSUL_SERVICE_NAME_KEY, value = "${spring.application.name}-hello-service")
                )
        }
)

Expected behavior

Actual behavior

1、程序启动后,异常如下 error1 2、程序正常退出后,consul未解除注册 error2

Steps to reproduce

Minimal yet complete reproducer code (or GitHub URL to code)

Environment

sofastack-bot[bot] commented 4 years ago

Hi @leyou240, we detect non-English characters in the issue. This comment is an auto translation by @sofastack-robot to help other users to understand this issue.

We encourage you to describe your issue in English which is more friendly to other users.

Describe the bug A clear and concise description of what the bug is. Use the [demo] provided by @ScienJus (https://github.com/ScienJus/sofa-rpc-consul-registry-demo) to increase the use of the rest protocol. . The service could not be unregistered normally, and there was an exception in the log after startup @SofaService( bindings = { @SofaServiceBinding( bindingType = "bolt" , parameters = @SofaParameter(key = ConsulConstants.CONSUL_SERVICE_NAME_KEY, value = "${spring. Application.name}-hello-service") ), @SofaServiceBinding( bindingType = "rest", parameters = @SofaParameter(key = ConsulConstants.CONSUL_SERVICE_NAME_KEY, value = "${spring.application.name}-hello-service") ) } ) ### Expected behavior ### Actual behavior 1. After the program starts, the exception is as follows![error1](https://user-images.githubusercontent.com/9214525/62356028-c17a5680-b542-11e9- 8f17-25187beec02f.png) 2. After the program exits normally, consul is not unregistered! error2 ### Steps to reproduce ### Minimal yet complete reproducer code (or GitHub URL to code) ### Environment - SOFARPC version: 5.6.0 - JVM version (eg java -version):openjdk version "1.8.0_212 -1-ojdkbu Ild" - OS version (eg uname -a):win10 - Maven version:3.6.1 - IDE version:idea 2019.2

ScienJus commented 4 years ago

Hi @leyou240 感谢反馈。

我看了一下,这个问题主要是 demo 中的 resteasy 版本依赖有问题,导致 rest provider 启动失败,启动失败后在关闭时也没有调用 registry 的 unRegister 方法,所以没有取消注册。

我在 demo 的 rest 分支中推了一个版本,和你本地的版本应该只差一个依赖项,你可以尝试运行一下。

leyou240 commented 4 years ago

OK! 图1的异常已经没有了。 但是正常关闭后(idea中exit),还是会有图2的情况 @ScienJus

ScienJus commented 4 years ago

@leyou240 图 2 我这里本地没有复现,可以尝试在本地打断点或是通过日志判断 ConsulRegistry#unRegister 是否有被调用两次么?

我这边本地启动时的 RPC Registry 日志:

2019-08-02 17:50:28,804 INFO  main                             com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00205: RPC 服务[com.scienjus.sofa.rpc.consul.HelloService]发布开始 
2019-08-02 17:50:28,811 INFO  main                             com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00201: 发布 RPC 服务:服务名[com.scienjus.sofa.rpc.consul.HelloService] 
2019-08-02 17:50:28,812 INFO  main                             com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00206: RPC 服务[com.scienjus.sofa.rpc.consul.HelloService]发布结束 
2019-08-02 17:50:28,813 INFO  main                             com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00205: RPC 服务[com.scienjus.sofa.rpc.consul.HelloService]发布开始 
2019-08-02 17:50:28,818 INFO  main                             com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00201: 发布 RPC 服务:服务名[com.scienjus.sofa.rpc.consul.HelloService] 
2019-08-02 17:50:28,818 INFO  main                             com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00206: RPC 服务[com.scienjus.sofa.rpc.consul.HelloService]发布结束 
2019-08-02 17:55:16,334 INFO  Thread-20                        com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00203: 注销 RPC 服务:服务名[com.scienjus.sofa.rpc.consul.HelloService] 数量[1] 
2019-08-02 17:55:16,334 INFO  SOFA-RPC-ShutdownHook            com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00203: 注销 RPC 服务:服务名[com.scienjus.sofa.rpc.consul.HelloService] 数量[1] 
2019-08-02 17:55:16,342 INFO  Thread-20                        com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00203: 注销 RPC 服务:服务名[com.scienjus.sofa.rpc.consul.HelloService] 数量[1] 
2019-08-02 17:55:16,343 INFO  SOFA-RPC-ShutdownHook            com.alipay.sofa.rpc.registry.consul.ConsulRegistry - RPC-00203: 注销 RPC 服务:服务名[com.scienjus.sofa.rpc.consul.HelloService] 数量[1] 

可以通过配置 logging.path 到你可以查看日志的路径。

leyou240 commented 4 years ago

我这边还是复现此问题,看了下日志确实如你所说。unRegister 了2次。 但是我看consul日志,似乎是重复unRegister了bolt协议的。 我自测了,无论是仅适用rest协议还是使用多个协议。都没去unRegister rest协议的服务。 如下为consul的日志,我的consul版本为1.5.3。 解除注册

ScienJus commented 4 years ago

@leyou240 有些神奇,能把修改后的 demo 推到某个仓库,我试着复现下么?

leyou240 commented 4 years ago

@ScienJus 我找到原因了,我之前在interface没有配置resteasy的注解。发布正常,但unRegister中的ids就无法正常获取到。 使用resteasy注解后,一切正常!