Skip to content

Commit 4b904b7

Browse files
committed
fix: mcp-keep-alive-scheduler thread not stop problem
1 parent d499f65 commit 4b904b7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

core/src/main/java/com/taobao/arthas/core/server/ArthasBootstrap.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public class ArthasBootstrap {
130130
private HttpApiHandler httpApiHandler;
131131

132132
private McpHttpRequestHandler mcpRequestHandler;
133+
private ArthasMcpBootstrap arthasMcpBootstrap;
133134

134135
private HttpSessionManager httpSessionManager;
135136
private SecurityAuthenticator securityAuthenticator;
@@ -474,8 +475,8 @@ private void bind(Configure configure) throws Throwable {
474475
if (mcpEndpoint != null && !mcpEndpoint.trim().isEmpty()) {
475476
logger().info("try to start mcp server, endpoint: {}, protocol: {}.", mcpEndpoint, mcpProtocol);
476477
CommandExecutor commandExecutor = new CommandExecutorImpl(sessionManager);
477-
ArthasMcpBootstrap arthasMcpBootstrap = new ArthasMcpBootstrap(commandExecutor, mcpEndpoint, mcpProtocol);
478-
this.mcpRequestHandler = arthasMcpBootstrap.start().getMcpRequestHandler();
478+
this.arthasMcpBootstrap = new ArthasMcpBootstrap(commandExecutor, mcpEndpoint, mcpProtocol);
479+
this.mcpRequestHandler = this.arthasMcpBootstrap.start().getMcpRequestHandler();
479480
}
480481
logger().info("as-server listening on network={};telnet={};http={};timeout={};mcp={};mcpProtocol={};", configure.getIp(),
481482
configure.getTelnetPort(), configure.getHttpPort(), options.getConnectionTimeout(), configure.getMcpEndpoint(), configure.getMcpProtocol());
@@ -526,6 +527,17 @@ public EnhancerAffect reset() throws UnmodifiableClassException {
526527
* call reset() before destroy()
527528
*/
528529
public void destroy() {
530+
if (this.arthasMcpBootstrap != null) {
531+
try {
532+
// stop 时需要主动关闭 mcp keep-alive 调度线程,避免 stop 后残留线程导致 ArthasClassLoader 无法回收
533+
this.arthasMcpBootstrap.shutdown();
534+
} catch (Throwable e) {
535+
logger().error("stop mcp server error", e);
536+
} finally {
537+
this.arthasMcpBootstrap = null;
538+
this.mcpRequestHandler = null;
539+
}
540+
}
529541
if (shellServer != null) {
530542
shellServer.close();
531543
shellServer = null;

0 commit comments

Comments
 (0)