fix crash on client disconnect (Ctrl+C)#4308
Merged
lvhan028 merged 3 commits intoInternLM:mainfrom Feb 2, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash that occurs when a client disconnects (e.g., via Ctrl+C) by improving exception handling in the async infrastructure. The changes address race conditions and ensure proper cleanup of resources during client disconnections.
Changes:
- Added a check to prevent setting a result on an already-completed future in the StreamingSemaphore
- Improved exception handling for client disconnects (asyncio.CancelledError, GeneratorExit) with proper async cancellation
- Added backend-specific cleanup logic for PyTorch backend in the safe_run exception handler
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lmdeploy/turbomind/turbomind.py | Adds future.done() check before setting result to prevent InvalidStateError on already-completed futures |
| lmdeploy/serve/managers/session_manager.py | Updates exception handling to catch CancelledError and GeneratorExit, removes redundant async_end call for SafeRunException, and improves logging consistency |
| lmdeploy/serve/core/async_engine.py | Adds PyTorch-specific session cleanup in safe_run exception handler to ensure proper resource release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
irexyc
approved these changes
Jan 30, 2026
lzhangzz
approved these changes
Feb 2, 2026
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.
No description provided.