Skip to content

Commit 8397849

Browse files
committed
Properly dispose Schedulers for IO and skip closing BufferedReader as they deadlocked on Ubuntu
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@gmail.com>
1 parent a4950c0 commit 8397849

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/stdio/StdioServerTransport.java

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -253,31 +253,13 @@ public Mono<Void> closeGracefully() {
253253
if (process.exitValue() != 0) {
254254
System.out.println("Process terminated with code " + process.exitValue());
255255
}
256-
}).then(Mono.whenDelayError(Mono.fromRunnable(() -> {
257-
try {
258-
this.processErrorReader.close();
259-
}
260-
catch (IOException e) {
261-
throw new RuntimeException(e);
262-
}
263-
}), Mono.fromRunnable(() -> {
264-
try {
265-
this.processReader.close();
266-
}
267-
catch (IOException e) {
268-
throw new RuntimeException(e);
269-
}
270-
}), Mono.fromRunnable(() -> {
271-
try {
272-
this.processWriter.close();
273-
}
274-
catch (IOException e) {
275-
throw new RuntimeException(e);
276-
}
277-
})))
278-
.then(Mono.whenDelayError(inboundScheduler.disposeGracefully(), outboundScheduler.disposeGracefully(),
279-
errorScheduler.disposeGracefully()))
280-
.subscribeOn(Schedulers.boundedElastic());
256+
}).then(Mono.fromRunnable(() -> {
257+
// The Threads are blocked on readLine so disposeGracefully would not
258+
// interrupt them, therefore we issue an async hard dispose.
259+
inboundScheduler.dispose();
260+
errorScheduler.dispose();
261+
outboundScheduler.dispose();
262+
})).then().subscribeOn(Schedulers.boundedElastic());
281263
}
282264

283265
}

0 commit comments

Comments
 (0)