modelcontextprotocol / modelcontextprotocol/java-sdk

StdioClientTransport: Inbound Scheduler and Error Scheduler threads are locked on Windows

Aberta
#759 1 comentário 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

bug P2
Linguagem predominante
Java
Estrelas
3.7k
Forks
1.1k
Merge médio
1d 15h
PRs com merge (30d)
9

Descrição

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

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.

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em io.modelcontextprotocol.client.transport.StdioClientTransport, concentrando-se no Inbound Scheduler, no Error Scheduler e no método closeGracefully; em seguida, analise o thread dump do Windows anexado em busca de leituras bloqueadas. Reproduza o Spring AI Filesystem Demo no Windows e verifique se o desligamento encerra o processo Java sem deixar threads do scheduler bloqueadas.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
java
Domínio
backend
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
38/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.