HttpServletStreamableServerTransportProvider leaves session sweeper thread alive after close
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 54/100
Rechercherichtung
Start in the HttpServletStreamableServerTransportProvider implementation, especially startSessionSweeper(), closeGracefully(), and destroy(); trace scheduler ownership and failed-start cleanup. Then inspect the transport lifecycle tests and add coverage for repeated create/close cycles, idle-session eviction, and active-stream close. Done means owned sweeper threads terminate on close while eviction continues during normal operation.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
Since MCP Java SDK 2.1.0, constructing and closing an
HttpServletStreamableServerTransportProvider leaves one live, non-daemon
streamable-http-server-transport-session-sweeper thread. Repeating the
create/close cycle accumulates threads and can prevent the JVM from exiting.
This reproduces without a servlet container or an MCP client.
Versions and result
Tested on JDK 25 with mcp-core and mcp-json-jackson2 at matching versions:
| Version | Live sweeper threads after one close |
|---|---|
| 2.0.1 | 0 (sweeper not present) |
| 2.1.0 | 1, non-daemon |
| 2.2.0 | 1, non-daemon |
The same behavior occurs when the transport is used in a real server: after
two start/stop cycles, two sweeper threads remain and the JVM does not exit.
Minimal reproduction
import com.fasterxml.jackson.databind.ObjectMapper;
import io.modelcontextprotocol.json.jackson2.JacksonMcpJsonMapper;
import io.modelcontextprotocol.server.transport.HttpServletStreamableServerTransportProvider;
public class SessionSweeperShutdownRepro {
public static void main(String[] args) throws Exception {
var provider = HttpServletStreamableServerTransportProvider.builder()
.jsonMapper(new JacksonMcpJsonMapper(new ObjectMapper()))
.mcpEndpoint("/mcp")
.build();
provider.closeGracefully().block();
Thread.sleep(250);
var sweepers = Thread.getAllStackTraces().keySet().stream()
.filter(Thread::isAlive)
.filter(thread -> thread.getName().startsWith(
"streamable-http-server-transport-session-sweeper"))
.toList();
System.out.println("Remaining sweepers: " + sweepers.size());
sweepers.forEach(thread -> System.out.println(
thread.getName() + " daemon=" + thread.isDaemon()));
}
}
Expected behavior
closeGracefully().block() (and destroy()) should stop transport-owned
background work. Repeated create/close cycles should not accumulate threads,
and the JVM should be able to exit normally. Session eviction must continue
to work while the provider is running.
Likely cause and suggested fix
startSessionSweeper() creates a dedicated Schedulers.newSingle(...) for
Flux.interval(...), but retains only the Flux subscription Disposable.
closeGracefully() disposes the subscription, not the scheduler, leaving its
non-daemon thread alive. destroy() delegates to the same close path.
Please retain ownership of the Scheduler and dispose it during normal close
and failed-start cleanup, alongside the subscription. Cleanup should be
idempotent. A regression test should cover repeated create/close cycles,
thread termination, continued idle-session eviction, and active-stream close.
Disabling session sweeping or merely making its thread daemon would conceal
the lifecycle bug and/or undo idle-session cleanup.
Related: #1130 introduced session sweeping. This is distinct from the
HttpClient SelectorManager leak in #620 and the disconnected-client socket
issue in #1021.
- Vorherrschende Sprache
- Java
- Sterne
- 3.8k
- Forks
- 1.1k
- Ø Merge
- 1 T. 3 Std.
- Gemergte PRs (30 T.)
- 38
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/java-sdk
-
Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON stringEvtl. vergeben @starryeye hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
modelcontextprotocol/java-sdk#1352 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was calledOffen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
modelcontextprotocol/java-sdk#1346 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
modelcontextprotocol/java-sdk#1345 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Tool result _meta is lost when the server automatically adds text content for structured outputOffenarea/server legacy P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
modelcontextprotocol/java-sdk#1330 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Client request handlers that complete empty send no JSON-RPC responseEvtl. vergeben @1fanwang hat das vor 83 Tagen übernommen. Offenarea/client bug P2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
modelcontextprotocol/java-sdk#1124 · 6 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in modelcontextprotocol/java-sdk
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
crash
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
-
account bug course exam iris lecture
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag