fix: ensure openConnections.dispose() runs in closeGracefully even if the handshake logic throws an exception or fails.#867
Closed
noxymon wants to merge 1 commit intomodelcontextprotocol:mainfrom
Closed
Conversation
… onClose errors - Updated DefaultMcpTransportSession#closeGracefully to use doFinally for connection disposal. - Added DefaultMcpTransportSessionTests to verify the fix.
Author
|
i think, the solution duplicated by #868 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR ensures that internal connections in DefaultMcpTransportSession are always disposed of during the graceful shutdown process, even if the handshake logic throws an exception or fails.
Motivation and Context
The previous implementation of closeGracefully() would skip the connection disposal step if the onClose function emitted an error. This led to resource leaks in scenarios where the server was unresponsive or the handshaking handshake handshaked
wrong. This fix uses Reactor's doFinally to guarantee cleanup.
This PR closes #547.
How Has This Been Tested?
Breaking Changes
None.
Types of changes
Checklist
Additional context
Used Mono.defer and doFinally to ensure reliable execution of the cleanup logic regardless of the reactive signal type.