{"record":{"id":"235e7eb1b852daa9","repo":"spring-projects/spring-ai","slug":"got-error-when-closing-transport","errorCode":null,"errorMessage":"Got error when closing transport","messagePattern":"Got error when closing transport","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"mcp/transport/mcp-spring-webflux/src/main/java/org/springframework/ai/mcp/client/webflux/transport/WebClientStreamableHttpTransport.java","lineNumber":184,"sourceCode":"\t\t\tthis.handler.set(handler);\n\t\t\tif (this.openConnectionOnStartup) {\n\t\t\t\tlogger.debug(\"Eagerly opening connection on startup\");\n\t\t\t\treturn this.reconnect(null).then();\n\t\t\t}\n\t\t\treturn Mono.empty();\n\t\t});\n\t}\n\n\tprivate McpTransportSession<Disposable> createTransportSession() {\n\t\tFunction<String, Publisher<Void>> onClose = sessionId -> sessionId == null ? Mono.empty()\n\t\t\t\t: this.webClient.delete()\n\t\t\t\t\t.uri(this.endpoint)\n\t\t\t\t\t.header(HttpHeaders.MCP_SESSION_ID, sessionId)\n\t\t\t\t\t.header(HttpHeaders.PROTOCOL_VERSION, this.latestSupportedProtocolVersion)\n\t\t\t\t\t.retrieve()\n\t\t\t\t\t.toBodilessEntity()\n\t\t\t\t\t.onErrorComplete(e -> {\n\t\t\t\t\t\tlogger.warn(\"Got error when closing transport\", e);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t})\n\t\t\t\t\t.then();\n\t\treturn new DefaultMcpTransportSession(onClose);\n\t}\n\n\t@Override\n\tpublic void setExceptionHandler(Consumer<Throwable> handler) {\n\t\tlogger.debug(\"Exception handler registered\");\n\t\tthis.exceptionHandler.set(handler);\n\t}\n\n\tprivate void handleException(Throwable t) {\n\t\tif (logger.isDebugEnabled()) {\n\t\t\tlogger.debug(\"Handling exception for session \" + sessionIdOrPlaceholder(this.activeSession.get()), t);\n\t\t}\n\t\tif (t instanceof McpTransportSessionNotFoundException) {\n\t\t\tMcpTransportSession<?> invalidSession = this.activeSession.getAndSet(createTransportSession());","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/mcp/transport/mcp-spring-webflux/src/main/java/org/springframework/ai/mcp/client/webflux/transport/WebClientStreamableHttpTransport.java#L166-L202","documentation":"WebClientStreamableHttpTransport.createTransportSession() builds a Mono that DELETEs the MCP endpoint when a transport session closes. Errors from that close request are logged at WARN ('Got error when closing transport') and swallowed via onErrorComplete — the close failure does not propagate to the caller.","triggerScenarios":"Any MCP client session over the streamable HTTP (WebFlux) transport being closed/disposed while the server is unreachable, has already terminated the session (404 on unknown session id), or rejects the DELETE (auth failure).","commonSituations":"MCP server restarted or redeployed, invalidating the session id; network drop during shutdown; server not implementing session termination; closing the client after the server already ended the session.","solutions":["Treat it as benign if it occurs during application shutdown against an already-dead server — the session is gone either way.","If frequent, verify the MCP server supports DELETE-based session termination per the MCP streamable HTTP spec.","Check connectivity/auth to this.endpoint and that the server honors the Mcp-Session-Id header.","Upgrade spring-ai MCP transport versions if the server returns unexpected status codes on close."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// already handled internally via onErrorComplete; on your side: mcpClient.close() inside try/finally and ignore close-time warnings","preventionTips":["Close MCP clients explicitly at shutdown so sessions terminate before the server disappears","Confirm the MCP server supports DELETE session termination (streamable HTTP spec)","Expect this WARN when the server restarted; reinitialize a fresh session instead of reusing the old one"],"tags":["mcp","webflux","transport","session-close","logging"],"backgroundTag":"http-error-response","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}