sofastack / sofa-boot

SOFABoot is a framework that enhances Spring Boot and fully compatible with it, provides readiness check, class isolation, etc.
https://www.sofastack.tech/sofa-boot/docs/Home
Apache License 2.0
4.92k stars 1.26k forks source link

fix #1276 after healthcheck double check success, register async #1290

Closed wangchengming666 closed 4 months ago

wangchengming666 commented 4 months ago

方案

rpc-sofa-boot里定义一个否允许延迟服务发布至注册中心的扩展点,然后在sofa-boot-actuator里判断应用的健康状态,通过后再继续注册到注册中心。

修复后验证

demo地址:https://github.com/wangchengming666/sofa-boot-delay-demo 需要在配置里加上这两行

sofa.boot.rpc.enable-auto-publish=true
sofa.boot.rpc.enable-delay-register=true

我的demo验证情况如下,我有一个接口配置了延时10s发布、然后应用启动后会2s循环调用一下,理论上前4~5次都会出现Cannot get the service address of service的异常,之后会正常调用,控制台日志打印如下

2024-02-23 14:50:39.740  INFO 66775 --- [           main] .b.s.StartupSpringApplicationRunListener : Started SOFABoot Demo in 2.556 seconds
com.alipay.sofa.rpc.core.exception.SofaRouteException: RPC-020060001: Cannot get the service address of service [com.example.sofabootprovider.HelloService:1.0], please check the registry log. 
    at com.alipay.sofa.rpc.client.AbstractCluster.noAvailableProviderException(AbstractCluster.java:502)
    at com.alipay.sofa.rpc.client.AbstractCluster.select(AbstractCluster.java:423)
    at com.alipay.sofa.rpc.client.FailoverCluster.doInvoke(FailoverCluster.java:67)
    at com.alipay.sofa.rpc.client.AbstractCluster.invoke(AbstractCluster.java:298)
    at com.alipay.sofa.rpc.client.ClientProxyInvoker.invoke(ClientProxyInvoker.java:83)
    at com.example.sofabootprovider.HelloService_proxy_0.sayHello(HelloService_proxy_0.java)
    at com.example.sofabootprovider.SofaBootProviderApplication.main(SofaBootProviderApplication.java:26)
com.alipay.sofa.rpc.core.exception.SofaRouteException: RPC-020060001: Cannot get the service address of service [com.example.sofabootprovider.HelloService:1.0], please check the registry log. 
    at com.alipay.sofa.rpc.client.AbstractCluster.noAvailableProviderException(AbstractCluster.java:502)
    at com.alipay.sofa.rpc.client.AbstractCluster.select(AbstractCluster.java:423)
    at com.alipay.sofa.rpc.client.FailoverCluster.doInvoke(FailoverCluster.java:67)
    at com.alipay.sofa.rpc.client.AbstractCluster.invoke(AbstractCluster.java:298)
    at com.alipay.sofa.rpc.client.ClientProxyInvoker.invoke(ClientProxyInvoker.java:83)
    at com.example.sofabootprovider.HelloService_proxy_0.sayHello(HelloService_proxy_0.java)
    at com.example.sofabootprovider.SofaBootProviderApplication.main(SofaBootProviderApplication.java:26)
com.alipay.sofa.rpc.core.exception.SofaRouteException: RPC-020060001: Cannot get the service address of service [com.example.sofabootprovider.HelloService:1.0], please check the registry log. 
    at com.alipay.sofa.rpc.client.AbstractCluster.noAvailableProviderException(AbstractCluster.java:502)
    at com.alipay.sofa.rpc.client.AbstractCluster.select(AbstractCluster.java:423)
    at com.alipay.sofa.rpc.client.FailoverCluster.doInvoke(FailoverCluster.java:67)
    at com.alipay.sofa.rpc.client.AbstractCluster.invoke(AbstractCluster.java:298)
    at com.alipay.sofa.rpc.client.ClientProxyInvoker.invoke(ClientProxyInvoker.java:83)
    at com.example.sofabootprovider.HelloService_proxy_0.sayHello(HelloService_proxy_0.java)
    at com.example.sofabootprovider.SofaBootProviderApplication.main(SofaBootProviderApplication.java:26)
com.alipay.sofa.rpc.core.exception.SofaRouteException: RPC-020060001: Cannot get the service address of service [com.example.sofabootprovider.HelloService:1.0], please check the registry log. 
    at com.alipay.sofa.rpc.client.AbstractCluster.noAvailableProviderException(AbstractCluster.java:502)
    at com.alipay.sofa.rpc.client.AbstractCluster.select(AbstractCluster.java:423)
    at com.alipay.sofa.rpc.client.FailoverCluster.doInvoke(FailoverCluster.java:67)
    at com.alipay.sofa.rpc.client.AbstractCluster.invoke(AbstractCluster.java:298)
    at com.alipay.sofa.rpc.client.ClientProxyInvoker.invoke(ClientProxyInvoker.java:83)
    at com.example.sofabootprovider.HelloService_proxy_0.sayHello(HelloService_proxy_0.java)
    at com.example.sofabootprovider.SofaBootProviderApplication.main(SofaBootProviderApplication.java:26)
2024-02-23T14:50:49.799+08:00  WARN 66775 --- [SOFABoot Demo] [           main] io.fury.config.FuryBuilder               : Class registration isn't forced, unknown classes can be deserialized. If the environment isn't secure, please enable class registration by `FuryBuilder#requireClassRegistration(true)` or configure ClassChecker by `ClassResolver#setClassChecker`
2024-02-23T14:50:49.850+08:00  INFO 66775 --- [SOFABoot Demo] [           main] io.fury.Fury                             : Created new fury io.fury.Fury@5c703860
hello world
hello world
hello world
hello world
hello world
hello world
hello world
codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 92.00000% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 83.13%. Comparing base (3502092) to head (88b06f7).

Files Patch % Lines
...fa/rpc/boot/container/ProviderConfigContainer.java 89.47% 0 Missing and 4 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1290 +/- ## ============================================ + Coverage 83.05% 83.13% +0.08% - Complexity 2927 2945 +18 ============================================ Files 330 331 +1 Lines 9625 9659 +34 Branches 1164 1168 +4 ============================================ + Hits 7994 8030 +36 + Misses 1126 1120 -6 - Partials 505 509 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.