You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: address Copilot AI review suggestions for disconnect cleanup
Changes based on Copilot AI review:
1. Fixed fallback path using temp event loop pattern:
- asyncio.run() may fail if there's already an event loop in current thread
- Now uses new_event_loop() + set_event_loop() + run_until_complete() pattern
- Preserves and restores original loop if one existed
2. Set references to None immediately after __aexit__:
- self._session = None after closing session
- self._stdio_context = None after closing context
- Prevents window where closed objects are still referenced
- Also clears on error to prevent reuse of broken objects
3. Added documentation for critical cleanup order:
- Session must close BEFORE stdio_context
- Session depends on streams provided by stdio_context
- Mirrors initialization order in _connect_stdio()
- Added warning comment to prevent future breakage
0 commit comments