Skip to content

bug: Runner.run_async tool_context may not be fully cleaned up on task cancellation #6271

Description

@tcconnally

Problem

When Runner.run_async() is cancelled mid-execution via asyncio.CancelledError, the tool_context resources (open connections, auth sessions, file handles) may not be properly cleaned up if the cleanup code doesn't handle CancelledError.

Impact

Each cancelled run can leak resources. Under repeated cancellation patterns (e.g., timeout-based cancellation in production), accumulated resource exhaustion can crash the runtime.

Suggestion

Consider wrapping cleanup in asyncio.shield() or ensuring the finally block catches CancelledError to guarantee cleanup runs even when the task is cancelled.

Metadata

Metadata

Assignees

Labels

request clarification[Status] The maintainer need clarification or more information from the authortools[Component] This issue is related to tools

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions