Sentinel sentinel-transport provent our shutdown, process was alive but CAN NOT provide service

vktxenjb  于 2021-11-29  发布在  Java
关注(0)|答案(0)|浏览(260)

Issue Description

Type: bug report

sentinel-transport will provent our shutdown

sentinel-transport will provent our shutdown(yes, the process still alive, but CAN NOT provide service) when *UNHANDLED * exception caused in ApplicationListener

Describe what you expected to happen

If exception was caused, we hope the process shutdown.

How to reproduce it (as minimally and precisely as possible)

add sentinel in pom.xml

<dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
            <version>${scp.version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-transport-simple-http</artifactId>
            <version>${scp.version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            <version>${alibabaspringcloud.version}</version>
        </dependency>
  1. make a UNHANDLED exception in ApplicationListener
@Component
public class ApplicationReadyListener implements ApplicationListener<ApplicationReadyEvent> {
    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        int i = 1/0;
    }
}

It SHOULD BE shutdown, but it's not. And we found a Thread was waiting something.
The thread name is sentine-time-tick-thread

If we manually invoke CommandCenter to stop, on ContextClosedEvent the application will shutdown as well.
Yet, GraceFulShutdownListener should added in spring.factories

/**
 * Created by danebrown on 2021/8/20
 * 
 *
 * @author danebrown
 */
public class GraceFulShutdownListener implements SmartApplicationListener {
    private static final Class<? extends ApplicationEvent>[] SUPPORT_APPLICATION_EVENT=
        new Class[]{ApplicationReadyEvent.class, ContextClosedEvent.class};
    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        return ObjectUtils.containsElement(SUPPORT_APPLICATION_EVENT,eventType);
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if(event instanceof ApplicationReadyEvent){

        }else if(event instanceof  ContextClosedEvent){

            try {
                CommandCenter commandCenter =
                        CommandCenterProvider.getCommandCenter();
                commandCenter.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.err.println("yep, you got a error");
        }

    }
}

Tell us your environment

OS:MacOsx/Windows/Linux
Software: spring boot:2.2.5-RELEASE
Sentinel:spring-cloud-starter-alibaba-sentinel/sentinel-transport-simple-http/sentinel-spring-cloud-gateway-adapter

Anything else we need to know?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题