-
Notifications
You must be signed in to change notification settings - Fork 336
fix(server): ensure DefaultRequestHandler cancels producer on blocking failure #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(server): ensure DefaultRequestHandler cancels producer on blocking failure #645
Conversation
Summary of ChangesHello @Wondr-design, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses a potential deadlock in on_message_send during blocking failures by ensuring the producer task is cancelled. The introduction of the success flag and the cancel parameter in _cleanup_producer is a clean approach. My review includes one suggestion to improve the exception handling within _cleanup_producer to prevent a CancelledError from masking the original failure exception, making the cleanup process more robust.
| """Cleans up the agent execution task and queue manager entry.""" | ||
| if cancel: | ||
| producer_task.cancel() | ||
| await producer_task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When cancel=True, producer_task.cancel() is called. Subsequently, await producer_task will raise an asyncio.CancelledError. This exception is currently unhandled. If _cleanup_producer is called from a finally block (as it is in on_message_send), this unhandled CancelledError can mask the original exception that led to the finally block executing. To prevent this and handle the expected cancellation gracefully, it's best to wrap the await in a try...except block.
| await producer_task | |
| try: | |
| await producer_task | |
| except asyncio.CancelledError: | |
| # This is expected if the task was cancelled, so we can ignore. | |
| pass |
Fixes #609.
This PR addresses an issue where
DefaultRequestHandler.on_message_sendwould hang indefinitely if the request failed or was cancelled while waiting for the agent execution in blocking mode. The previous implementation waited for the producer task to finish in thefinallyblock without cancelling it, leading to a deadlock if the agent was still running (e.g., stuck or long-running).Changes:
DefaultRequestHandler._cleanup_producerto accept an optionalcancelargument.DefaultRequestHandler.on_message_sendto cancel the producer task if the request fails (exception raised) or is cancelled (e.g., client timeout) while in blocking mode.Verification:
a2a/server/request_handlersand they passed.Type of Change: