Conversation
Signed-off-by: abrar <abrar@anyscale.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses the handling of task cancellation errors by simulating a TaskCancelledError in tests and converting it to an asyncio.CancelledError in production code. Key changes include:
- Adding a special case in the test helper to raise TaskCancelledError.
- Introducing a new test to verify the conversion of TaskCancelledError to asyncio.CancelledError.
- Updating the replica wrapper to catch TaskCancelledError and re-raise it as asyncio.CancelledError.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/ray/serve/tests/test_actor_replica_wrapper.py | Simulates TaskCancelledError in test flow and adds a corresponding unit test. |
| python/ray/serve/_private/request_router/replica_wrapper.py | Adds exception handling for TaskCancelledError to convert it into asyncio.CancelledError. |
Comment on lines
+119
to
+121
| except TaskCancelledError: | ||
| logger.info("Request already cancelled.") | ||
| raise asyncio.CancelledError() |
There was a problem hiding this comment.
Consider capturing the caught TaskCancelledError (e.g., 'except TaskCancelledError as err:') and re-raising the asyncio.CancelledError with exception chaining (using 'from err') to preserve the original error context for easier debugging.
Suggested change
| except TaskCancelledError: | |
| logger.info("Request already cancelled.") | |
| raise asyncio.CancelledError() | |
| except TaskCancelledError as err: | |
| logger.info("Request already cancelled.") | |
| raise asyncio.CancelledError() from err |
Signed-off-by: abrar <abrar@anyscale.com>
edoakes
approved these changes
Jun 10, 2025
elliot-barn
pushed a commit
that referenced
this pull request
Jun 18, 2025
don't know for sure, but seems like a race condition between when the cancel happens and attempt to access the ray task result causes `RayTaskCancelled` exception. Used the repro script in the ticket to confirm that the issue is resolved #53639. --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
elliot-barn
pushed a commit
that referenced
this pull request
Jul 2, 2025
don't know for sure, but seems like a race condition between when the cancel happens and attempt to access the ray task result causes `RayTaskCancelled` exception. Used the repro script in the ticket to confirm that the issue is resolved #53639. --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
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.
don't know for sure, but seems like a race condition between when the cancel happens and attempt to access the ray task result causes
RayTaskCancelledexception.Used the repro script in the ticket to confirm that the issue is resolved #53639.