adityamparikh opened a new issue, #325:
URL: https://github.com/apache/solr-mcp/issues/325

   ## Problem
   
   The MCP spec has a client shut down a STDIO server by closing its stdin. The 
server then exits, or the client sends `SIGTERM` and, if that doesn't work, 
`SIGKILL` ([lifecycle: 
shutdown](https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#shutdown)).
   
   Solr MCP Server exits on stdin EOF only if no tool has reached Solr yet. 
After any Solr call, for example a single `list-collections`, the process keeps 
running after stdin closes. This happens with the JVM jar and the native image, 
and in both STDIO modes (the default `streamable` and `MCP_PROTOCOL=modern`):
   
   | Session before stdin closes | Result |
   |---|---|
   | nothing, `server/discover`, or `tools/list` | exits in 0.1–0.4 s |
   | one `list-collections` call | still running 20 s later |
   
   A client that follows the spec still ends the process, but only after its 
timeout and a `SIGTERM`. With `docker run -i`, if the client force-kills the 
`docker` CLI, the signal never reaches the container, which keeps running with 
no client.
   
   ## Cause
   
   A thread dump of the stuck process shows only four 
`HttpJdkSolrClient-1-thread-N` threads holding the JVM open. When SolrJ 10's 
`HttpJdkSolrClient` isn't given an executor, it creates one with four core 
threads from `SolrNamedThreadFactory`, which calls `setDaemon(false)`. Those 
threads start on the first request, never time out, and are shut down only in 
`SolrClient.close()`.
   
   Nothing closes the Spring context when stdin reaches EOF. The 2025 STDIO 
transport shuts down its own threads and the modern one's threads are daemon 
threads, but neither tells the application. So `close()` never runs, and the 
pool keeps the JVM alive.
   
   ## Since when
   
   The `HttpJdkSolrClient` pool came with the SolrJ 10 upgrade (#58, 
2026-03-24); that version is the one measured above. Before that, the Jetty 
`Http2SolrClient` used since 2025-09-07 also built a non-daemon pool (`h2sc`, 
32 core threads), so it probably had the same problem. That earlier version 
hasn't been tested.
   
   ## Fix
   
   Give `HttpJdkSolrClient` an executor with daemon threads, sized like SolrJ's 
own pool, and register it as a bean so the context shuts it down. When stdin 
closes, the JVM then exits the same way it already does for sessions that never 
reach Solr, and Spring's shutdown hook still closes the Solr client. HTTP mode 
is unaffected because Tomcat's threads keep it running.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to