Uh oh!
There was an error while loading. Please reload this page.
Fix connection closure handling in Protocol and InMemoryTransport - #833
Fix connection closure handling in Protocol and InMemoryTransport#833alasano wants to merge 2 commits into
Conversation
- Make close() idempotent with _isClosed flag - Prevent infinite recursion by clearing _otherTransport before calling peer.close() - Ensure both transports' onclose callbacks fire - Add tests for idempotency, concurrent closes, and post-close behavior Fixes deadlock where closing one transport would not properly close its peer, causing promises to hang indefinitely.
- Track request handlers with AbortControllers in _requestHandlerAbortControllers - Abort all active request handlers in _onclose() to prevent hanging operations - Ensure both outgoing requests (response handlers) and incoming requests (request handlers) are properly terminated Fixes issue where request handlers would continue running after connection closure, causing timeouts and resource leaks.
alasano
commented
Aug 17, 2025
Hey @ihrpr , this PR fixes critical bugs causing indefinite connection hangs in multi-user scenarios. The fixes are also non-breaking with proper test coverage. Could you please review when you have time? Or assign someone else if possible, we've been running our own version with the fix but need it in the official package ideally. |
ihrpr
left a comment
There was a problem hiding this comment.
Thank you so much for the fixes!
Please can tests be added for the Protocol abort functionality as well?
alasano
commented
Aug 18, 2025
Thank you for getting back to me as well 🙏 Absolutely, I'll add some a bit later today |
markdascher
commented
Nov 24, 2025
Would #611 be fixed by this PR? |
Fix connection closure handling in Protocol and InMemoryTransport
Motivation and Context
This PR fixes two critical bugs that cause promises to hang indefinitely when connections are closed:
onclosecallback was never fired, causing server-side promises to hang foreverThese bugs manifested as timeout errors in applications where connections were closed while requests were in-flight (e.g., user disconnection during a pending UI prompt).
How Has This Been Tested?
elicitation/createrequestelicitation/create) would cause tests to hang indefinitelyBreaking Changes
None. These are bug fixes that make the SDK behave as expected.
Types of changes
Checklist
Additional context
The fix ensures proper cleanup in both directions:
onclosecallbacks