Properly dispose Schedulers for IO and skip closing BufferedReader as they deadlocked on Ubuntu

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@gmail.com>
This commit is contained in:
Dariusz Jędrzejczyk 2024-12-12 22:53:27 +01:00
commit 8397849d6e

View file

@ -253,31 +253,13 @@ public class StdioServerTransport extends AbstractMcpTransport {
if (process.exitValue() != 0) { if (process.exitValue() != 0) {
System.out.println("Process terminated with code " + process.exitValue()); System.out.println("Process terminated with code " + process.exitValue());
} }
}).then(Mono.whenDelayError(Mono.fromRunnable(() -> { }).then(Mono.fromRunnable(() -> {
try { // The Threads are blocked on readLine so disposeGracefully would not
this.processErrorReader.close(); // interrupt them, therefore we issue an async hard dispose.
} inboundScheduler.dispose();
catch (IOException e) { errorScheduler.dispose();
throw new RuntimeException(e); outboundScheduler.dispose();
} })).then().subscribeOn(Schedulers.boundedElastic());
}), 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());
} }
} }