Skip to content

fix: guard transport.close() with try/finally in Query.close()#959

Closed
itxaiohanglover wants to merge 1 commit into
anthropics:mainfrom
itxaiohanglover:fix/886-close-try-finally
Closed

fix: guard transport.close() with try/finally in Query.close()#959
itxaiohanglover wants to merge 1 commit into
anthropics:mainfrom
itxaiohanglover:fix/886-close-try-finally

Conversation

@itxaiohanglover
Copy link
Copy Markdown

@itxaiohanglover itxaiohanglover commented May 15, 2026

Summary

  • Wrap the cleanup steps in Query.close() with try/finally so that transport.close() always runs, even if a preceding step (batcher close, task cancellation/wait, message send close) raises an exception.
  • Without this fix, an exception during cleanup leaves the stderr reader task and CLI subprocess un-reaped.

Closes #886

Test plan

  • All 33 existing tests in tests/test_query.py pass
  • All 65 existing tests in tests/test_client.py pass
  • All 98 existing tests in tests/test_transport.py pass
  • ruff check and ruff format pass
  • mypy type checking passes

If any cleanup step preceding transport.close() raises an exception
(e.g. batcher.close(), task.wait(), message_send.close()), the
transport is never closed, leaving the stderr reader task and CLI
subprocess leaked. Wrap cleanup in try/finally to ensure transport
teardown always runs.

Closes anthropics#886
@itxaiohanglover
Copy link
Copy Markdown
Author

Closing as duplicate of #887 which already addresses this issue. Apologies for the oversight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query.close(): transport.close() not guarded by try/finally — can be skipped if earlier cleanup raises

1 participant