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

[feature request] make sentinel client close resources more easier and elegant #2178

Closed
Anilople opened this issue Apr 29, 2021 · 4 comments · Fixed by #2181
Closed

[feature request] make sentinel client close resources more easier and elegant #2178

Anilople opened this issue Apr 29, 2021 · 4 comments · Fixed by #2181
Labels
kind/enhancement Category issues or prs related to enhancement.

Comments

@Anilople
Copy link
Contributor

Issue Description

Type: feature request

Describe what happened (or what feature you want)

User can close sentinel client's resouces manually.

Describe what you expected to happen

User can use com.alibaba.csp.sentinel.init.InitExecutor.doInit() to init sentinel client.

Sometimes user want to close all resources in it.

Because some InitFunc will start a thread executor, and user may don't know how to close them.

For example, if user use sentinel-transport-simple-http, com.alibaba.csp.sentinel.transport.init.CommandCenterInitFunc will use com.alibaba.csp.sentinel.transport.command.SimpleHttpCommandCenter, there are 2 ExecutorService in it, user must write code to close it

		CommandCenter commandCenter = CommandCenterProvider.getCommandCenter();
		commandCenter.stop();

To make it more easier, should sentinel's client support a method to do it?

Like CloseExecutor.doClose().

Tell us your environment

OS: Centos 7.8
Jdk: 8
Sentinel Version: 1.8.0

Anything else we need to know?

When someone use Spring Cloud Alibaba Sentinel,
shutdown in actuator endpoint would be not working.

The reason is that ExecutorService in com.alibaba.csp.sentinel.transport.command.SimpleHttpCommandCenter prevents JVM to stop.

@Anilople
Copy link
Contributor Author

It seems that infinite loops while (true) in

public void run() {
while (true) {
Socket socket = null;
try {
socket = this.serverSocket.accept();
setSocketSoTimeout(socket);
HttpEventTask eventTask = new HttpEventTask(socket);
bizExecutor.submit(eventTask);
} catch (Exception e) {
CommandCenterLog.info("Server error", e);
if (socket != null) {
try {
socket.close();
} catch (Exception e1) {
CommandCenterLog.info("Error when closing an opened socket", e1);
}
}
try {
// In case of infinite log.
Thread.sleep(10);
} catch (InterruptedException e1) {
// Indicates the task should stop.
break;
}
}
}

prevents JVM to stop.

@Anilople
Copy link
Contributor Author

Maybe we can change those thread to daemon thread?

Change


to

new NamedThreadFactory("sentinel-command-center-executor", true)); 


to

new NamedThreadFactory("sentinel-command-center-service-executor", true),

That will let jvm close when user thread finished.

@sczyh30 sczyh30 added the kind/enhancement Category issues or prs related to enhancement. label Apr 30, 2021
@sczyh30
Copy link
Member

sczyh30 commented Apr 30, 2021

Maybe we can change those thread to daemon thread?

Change

to

new NamedThreadFactory("sentinel-command-center-executor", true)); 

to

new NamedThreadFactory("sentinel-command-center-service-executor", true),

That will let jvm close when user thread finished.

Good idea. Fancy a PR to improve it?

@wutingjia
Copy link
Contributor

please assign to me for practicing PR ~~~~(>_<)~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants