From 8397849d6efd70bd7dfee7ea8b088bb754b4e563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20J=C4=99drzejczyk?= Date: Thu, 12 Dec 2024 22:53:27 +0100 Subject: [PATCH] Properly dispose Schedulers for IO and skip closing BufferedReader as they deadlocked on Ubuntu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dariusz Jędrzejczyk --- .../client/stdio/StdioServerTransport.java | 32 ++++--------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/stdio/StdioServerTransport.java b/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/stdio/StdioServerTransport.java index a33c77c..6d176c7 100644 --- a/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/stdio/StdioServerTransport.java +++ b/spring-ai-mcp-core/src/main/java/org/springframework/ai/mcp/client/stdio/StdioServerTransport.java @@ -253,31 +253,13 @@ public class StdioServerTransport extends AbstractMcpTransport { if (process.exitValue() != 0) { System.out.println("Process terminated with code " + process.exitValue()); } - }).then(Mono.whenDelayError(Mono.fromRunnable(() -> { - try { - this.processErrorReader.close(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - }), Mono.fromRunnable(() -> { - try { - this.processReader.close(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - }), Mono.fromRunnable(() -> { - try { - this.processWriter.close(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - }))) - .then(Mono.whenDelayError(inboundScheduler.disposeGracefully(), outboundScheduler.disposeGracefully(), - errorScheduler.disposeGracefully())) - .subscribeOn(Schedulers.boundedElastic()); + }).then(Mono.fromRunnable(() -> { + // The Threads are blocked on readLine so disposeGracefully would not + // interrupt them, therefore we issue an async hard dispose. + inboundScheduler.dispose(); + errorScheduler.dispose(); + outboundScheduler.dispose(); + })).then().subscribeOn(Schedulers.boundedElastic()); } } \ No newline at end of file