alibaba / alibaba/Sentinel

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

Open
#2,345 0 comments 0 reactions 0 assignees View on GitHub
kind/question
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

## 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)

1.
add sentinel in pom.xml
```

com.alibaba.csp
sentinel-spring-cloud-gateway-adapter
${scp.version}


com.alibaba.csp
sentinel-transport-simple-http
${scp.version}


com.alibaba.cloud
spring-cloud-starter-alibaba-sentinel
${alibabaspringcloud.version}

```
2. make a *UNHANDLED* exception in ApplicationListener
```
@Component
public class ApplicationReadyListener implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
int i = 1/0;
}
}
```
3.
It SHOULD BE shutdown, but it's not. And we found a Thread was waiting something.
The thread name is *sentine-time-tick-thread*
![image](https://user-images.githubusercontent.com/1415402/130231010-afaffe16-2480-45d1-8d6e-209222ee371b.png)

4.
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[] SUPPORT_APPLICATION_EVENT=
new Class[]{ApplicationReadyEvent.class, ContextClosedEvent.class};
@Override
public boolean supportsEventType(Class 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?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with the listed Sentinel dependencies and an exception in ApplicationListener. Inspect the sentinel-time-tick-thread behavior and the shown GraceFulShutdownListener around ApplicationReadyEvent and ContextClosedEvent. Done means an unhandled startup exception causes the process to shut down rather than remain alive without serving requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.