modelcontextprotocol / modelcontextprotocol/java-sdk
StdioClientTransport: Inbound Scheduler and Error Scheduler threads are locked on Windows
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 3.7k
- Fork
- 1.1k
- Merge medio
- 1g 15h
- PR unite (30g)
- 9
Descrizione
Bug description
Two threads, Inbound Scheduler and Error Scheduler, remain locked forever (at java.io.FileInputStream.readBytes native call) in io.modelcontextprotocol.client.transport.StdioClientTransport after the graceful shutdown is completed using closeGracefully method.
Looks like a Windows specific issue with native I/O calls. The problem is observed when running on Windows. No problems with Linux environment.
The thread dump is attached.
dump_jdk17.txt
See "pool-2-thread-1" and "pool-5-thread-1" dumps.
Environment
Windows 11 Enterprise
mcp-core 0.17.1
Spring AI 2.0.0-SNAPSHOT
JDK Temurin 17.0.14 (also tried Amazon Corretto 21.0.5)
Linux Behavior
Works fine under Ubuntu 24.04 and JDK Temurin 21.0.10
Steps to reproduce
- Run the steps from the Spring AI Filesystem Demo example on Windows.
- The Java application process is not terminated as expected.
Expected behavior
The Java process terminates after running the Spring AI Filesystem Demo example.
Possible solution
On Windows, use daemon threads for inbound and error schedulers
private ThreadFactory daemonThreadFactory = runnable -> {
Thread t = new Thread(runnable);
t.setDaemon(true);
return t;
};
if (isWindows) {
this.inboundScheduler = Schedulers.fromExecutorService(Executors.newSingleThreadExecutor(daemonThreadFactory), "inbound");
this.errorScheduler = Schedulers.fromExecutorService(Executors.newSingleThreadExecutor(daemonThreadFactory), "error");
}
Tried this solution locally. It resolves the termination issue. But the graceful shutdown logic in io.modelcontextprotocol.client.transport.StdioClientTransport#closeGracefully should be revised as well.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da io.modelcontextprotocol.client.transport.StdioClientTransport, concentrandoti su Inbound Scheduler, Error Scheduler e sul metodo closeGracefully, quindi esamina il thread dump di Windows allegato alla ricerca di letture bloccate. Riproduci Spring AI Filesystem Demo su Windows e verifica che l’arresto termini il processo Java senza lasciare bloccati i thread dello scheduler.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100