Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove closed sessions from list in WebMvcSseServerTransport #19

Merged

Conversation

denniskawurek
Copy link
Contributor

@denniskawurek denniskawurek commented Feb 22, 2025

Remove a session from the session list in WebMvcSseServerTransport when it times out or closes.

Motivation and Context

This is related to: spring-projects/spring-ai#2267

When a client closes its connection then the session is still kept in the list of sessions. The transport then tries to broadcast messages to the outdated sessions and it fails with exception:

Failed to send message to session 6b973076-58fe-4613-95ba-3f39440f6ed0: Cannot invoke "org.apache.catalina.connector.OutputBuffer.isBlocking()" because "this.ob" is null

How Has This Been Tested?

Unfortunately the active sessions can't be retrieved from within a test, so manual testing was done.

I created a client - server application where 100 clients connect to a server and close their connection after doing a tool request.

2025-02-22T15:23:14.835+01:00 DEBUG 396597 --- [mcp-server-basic] [io-8080-exec-10] i.m.s.t.WebMvcSseServerTransport         : Attempting to broadcast message to 100 active sessions

After that another 100 clients do the same and the number of active sessions grows (although it should be 100):

2025-02-22T15:24:09.244+01:00 DEBUG 396597 --- [mcp-server-basic] [io-8080-exec-26] i.m.s.t.WebMvcSseServerTransport         : Attempting to broadcast message to 200 active sessions

Also, the following exception is thrown for each old, inactive session.

2025-02-22T15:24:09.244+01:00 ERROR 396597 --- [mcp-server-basic] [io-8080-exec-22] i.m.s.t.WebMvcSseServerTransport         : Failed to send message to session 6b973076-58fe-4613-95ba-3f39440f6ed0: Cannot invoke "org.apache.catalina.connector.OutputBuffer.isBlocking()" because "this.ob" is null

With the provided fix the sessions are removed from the list via callbacks on timeout and on complete.
The exception doesn't appear anymore.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@tzolov tzolov self-assigned this Feb 25, 2025
Copy link
Contributor

@tzolov tzolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you @denniskawurek

@tzolov tzolov merged commit bb6514e into modelcontextprotocol:main Feb 25, 2025
@tzolov tzolov added bug Something isn't working server labels Feb 26, 2025
@tzolov tzolov added this to the 0.8.0 milestone Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants