Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring boot 3 服务关闭时反注册失败! #1252

Open
lingting opened this issue Mar 26, 2024 · 13 comments
Open

spring boot 3 服务关闭时反注册失败! #1252

lingting opened this issue Mar 26, 2024 · 13 comments
Labels
enhancement New feature or request

Comments

@lingting
Copy link

Describe the bug
spring boot 3 服务关闭时, 注册中心反注册时报错.

To Reproduce
Steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

Environment

  • Version: 1.13.1-2023.0.0
  • OS: win11
  • jdk: 17

Additional context
2024-03-26 10:29:05.444 WARN 9596 --- [] [ngApplicationShutdownHook] l.lingting.framework.grpc.GrpcServer : shutdown grpc server!
2024-03-26 10:29:06.473 INFO 9596 --- [] [ngApplicationShutdownHook] l.l.polaris.grpc.server.GraceOffline : [grpc-polaris] begin grace shutdown
2024-03-26 10:29:14.476 DEBUG 9596 --- [] [ngApplicationShutdownHook] l.l.s.event.SpringContextClosedListener : spring context closed
2024-03-26 10:29:14.476 DEBUG 9596 --- [] [ngApplicationShutdownHook] l.l.s.event.SpringContextClosedListener : context component stop before
2024-03-26 10:29:14.476 DEBUG 9596 --- [] [ngApplicationShutdownHook] l.l.s.event.SpringContextClosedListener : context component stop
2024-03-26 10:29:14.476 WARN 9596 --- [] [ngApplicationShutdownHook] l.lingting.framework.grpc.GrpcServer : shutdown grpc server!
2024-03-26 10:29:14.476 INFO 9596 --- [] [ngApplicationShutdownHook] l.l.polaris.grpc.server.GraceOffline : [grpc-polaris] begin grace shutdown
2024-03-26 10:29:22.478 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483647
2024-03-26 10:29:22.478 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Bean 'applicationTaskExecutor' completed its stop procedure
2024-03-26 10:29:22.479 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147482623
2024-03-26 10:29:22.479 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Bean 'webServerGracefulShutdown' completed its stop procedure
2024-03-26 10:29:22.479 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147481599
2024-03-26 10:29:22.479 INFO 9596 --- [] [ngApplicationShutdownHook] io.undertow : stopping server: Undertow - 2.3.10.Final
2024-03-26 10:29:22.481 INFO 9596 --- [] [ngApplicationShutdownHook] io.undertow.servlet : Destroying Spring FrameworkServlet 'dispatcherServlet'
2024-03-26 10:29:22.482 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Bean 'webServerStartStop' completed its stop procedure
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Successfully stopped bean 'refreshScopeLifecycle'
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Polaris-metadata' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Polaris-config' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Polaris-discovery' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Beans' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Caches' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Health' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Info' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Conditions' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Shutdown' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Configprops' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Env' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Loggers' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Threaddump' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Metrics' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Scheduledtasks' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Mappings' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Refresh' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Restart' from the JMX domain
2024-03-26 10:29:22.483 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Pause' from the JMX domain
2024-03-26 10:29:22.484 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Resume' from the JMX domain
2024-03-26 10:29:22.484 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Features' from the JMX domain
2024-03-26 10:29:22.484 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.b.a.e.jmx.JmxEndpointExporter : Unregister endpoint with ObjectName 'org.springframework.boot:type=Endpoint,name=Serviceregistry' from the JMX domain
2024-03-26 10:29:22.484 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2024-03-26 10:29:22.484 DEBUG 9596 --- [] [ngApplicationShutdownHook] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2024-03-26 10:29:22.484 INFO 9596 --- [] [ngApplicationShutdownHook] c.t.c.p.registry.PolarisServiceRegistry : De-registering from Polaris Server now...
2024-03-26 10:29:22.484 ERROR 9596 --- [] [ngApplicationShutdownHook] c.t.c.p.registry.PolarisServiceRegistry : ERR_POLARIS_DEREGISTER, de-register failed...PolarisRegistration{ polarisDiscoveryProperties=PolarisDiscoveryProperties{namespace='boot', service='service-authorization', instanceId='null', token='null', weight=100, version='1.0.0', protocol='http', enabled=true, registerEnabled=true, heartbeatInterval=5, healthCheckUrl='', serviceListRefreshInterval=60000}, polarisContext=com.tencent.polaris.client.api.SDKContext@74b1db72, staticMetadataManager=StaticMetadataManager{envMetadata={}, envTransitiveMetadata={}, configMetadata={}, configTransitiveMetadata={}, configTransHeaders='null', customSPIMetadata={source_service_namespace=boot, source_service_name=service-authorization}, customSPITransitiveMetadata={}, mergedStaticMetadata={source_service_namespace=boot, source_service_name=service-authorization}, mergedStaticTransitiveMetadata={}, zone='null', region='null', campus='null'}, metadata={source_service_namespace=boot, source_service_name=service-authorization, internal-address=192.168.91.1:0, internal-ip=192.168.91.1}, host='192.168.91.1', instanceId='089cc2397242c5ed7d435f17c8bc65d657b6e920'},

com.tencent.polaris.api.exception.PolarisException: ERR-1005(INVALID_STATE): Plugin grpc has been destroyed
at com.tencent.polaris.api.control.Destroyable.checkDestroyed(Destroyable.java:73) ~[polaris-model-1.15.0.jar:na]
at com.tencent.polaris.plugins.connector.grpc.GrpcConnector.deregisterInstance(GrpcConnector.java:491) ~[connector-polaris-grpc-1.15.0.jar:na]
at com.tencent.polaris.discovery.client.flow.DefaultDiscoveryFlow.deRegister(DefaultDiscoveryFlow.java:195) ~[polaris-discovery-client-1.15.0.jar:na]
at com.tencent.polaris.discovery.client.api.DefaultProviderAPI.deRegister(DefaultProviderAPI.java:64) ~[polaris-discovery-client-1.15.0.jar:na]
at com.tencent.cloud.polaris.registry.PolarisServiceRegistry.deregister(PolarisServiceRegistry.java:193) ~[spring-cloud-starter-tencent-polaris-discovery-1.13.1-2023.0.0.jar:1.13.1-2023.0.0]
at com.tencent.cloud.polaris.registry.PolarisServiceRegistry.deregister(PolarisServiceRegistry.java:64) ~[spring-cloud-starter-tencent-polaris-discovery-1.13.1-2023.0.0.jar:1.13.1-2023.0.0]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.deregister(AbstractAutoServiceRegistration.java:281) ~[spring-cloud-commons-4.1.0.jar:4.1.0]
at com.tencent.cloud.polaris.registry.PolarisAutoServiceRegistration.deregister(PolarisAutoServiceRegistration.java:95) ~[spring-cloud-starter-tencent-polaris-discovery-1.13.1-2023.0.0.jar:1.13.1-2023.0.0]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.stop(AbstractAutoServiceRegistration.java:299) ~[spring-cloud-commons-4.1.0.jar:4.1.0]
at org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.destroy(AbstractAutoServiceRegistration.java:233) ~[spring-cloud-commons-4.1.0.jar:4.1.0]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMethod.invoke(InitDestroyAnnotationBeanPostProcessor.java:457) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeDestroyMethods(InitDestroyAnnotationBeanPostProcessor.java:415) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeDestruction(InitDestroyAnnotationBeanPostProcessor.java:239) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:202) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1202) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1195) ~[spring-beans-6.1.4.jar:6.1.4]
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1183) ~[spring-context-6.1.4.jar:6.1.4]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1144) ~[spring-context-6.1.4.jar:6.1.4]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:174) ~[spring-boot-3.2.3.jar:3.2.3]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1090) ~[spring-context-6.1.4.jar:6.1.4]
at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:145) ~[spring-boot-3.2.3.jar:3.2.3]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:114) ~[spring-boot-3.2.3.jar:3.2.3]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

2024-03-26 10:29:22.487 INFO 9596 --- [] [ngApplicationShutdownHook] c.t.c.p.registry.PolarisServiceRegistry : De-registration finished.
2024-03-26 10:29:22.487 INFO 9596 --- [] [ Thread-13] c.t.c.p.c.PolarisSDKContextManager : Polaris SDK context is destroyed.

@lingting lingting added the bug Something isn't working label Mar 26, 2024
@SkyeBeFreeman
Copy link
Collaborator

是不是同时使用了grpc-polaris和sct呢?

@lingting
Copy link
Author

lingting commented Mar 26, 2024 via email

@SkyeBeFreeman
Copy link
Collaborator

这个场景我晚点验证下,看日志像是grpc-polaris提前把grpc连接器插件销毁了,导致sct反注册的时候找不到grpc连接器插件,进而报错。

@lingting
Copy link
Author

lingting commented Mar 26, 2024 via email

@SkyeBeFreeman
Copy link
Collaborator

目前暂未针对这种场景作出兼容。如果分开使用的话,可能会一个实例服务注册两次。后续可能要考虑融合使用的接入方式。

@lingting
Copy link
Author

lingting commented Mar 26, 2024 via email

@SkyeBeFreeman
Copy link
Collaborator

@lingting grpc和sct的SDKcontext的连接器理论上是分开的,所以不应该有影响才对。可以debug看下,两者的connector是什么时候destroy的。

@lingting
Copy link
Author

@lingting grpc和sct的SDKcontext的连接器理论上是分开的,所以不应该有影响才对。可以debug看下,两者的connector是什么时候destroy的。

也就是在设计上 sct和grpc应该使用两个sdkcontext? 现在我是让它们使用的同一个sdkcontext

@SkyeBeFreeman
Copy link
Collaborator

grpc接入,你是自己实现的吗?使用这个框架,理论上来说sdkcontext是分开的,https://github.com/polarismesh/grpc-java-polaris

@lingting
Copy link
Author

grpc接入,你是自己实现的吗?使用这个框架,理论上来说sdkcontext是分开的,https://github.com/polarismesh/grpc-java-polaris

fork的这个, 不过这个的sdk初始化有问题, 没有读取spring的配置. 所以我在初始化的时候使用 com.tencent.cloud.polaris.context.PolarisSDKContextManager#getSDKContext 指定. 我看sdk的 destory 方法 com.tencent.polaris.api.control.Destroyable#destroy 有做判断, 应该只会调用一次才对.

@lingting
Copy link
Author

看起来是 com.tencent.polaris.plugins.connector.grpc.GrpcConnector#deregisterInstance 中 调用了 checkDestroyed 方法导致的异常. 应该还是反注册了2次.

@lingting
Copy link
Author

调用 同一个实例的 com.tencent.polaris.plugins.connector.grpc.GrpcConnector#registerInstance 注册了两次(一次http, 一次grpc). 然后反注册也是调用了2次

@SkyeBeFreeman
Copy link
Collaborator

SkyeBeFreeman commented May 10, 2024

@lingting 这样的话还是得分开两个SDKcontext。或者针对这个场景做一个功能。让sct新增一个支持grpc的starter。如果您有兴趣,可以贡献代码到sct仓库~

@SkyeBeFreeman SkyeBeFreeman added enhancement New feature or request and removed bug Something isn't working labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants