Skip to content

Add note about http client ownership to client docstrings#298

Merged
anuraaga merged 4 commits into
connectrpc:mainfrom
dongjiang1989:fix-sync-close
Jul 14, 2026
Merged

Add note about http client ownership to client docstrings#298
anuraaga merged 4 commits into
connectrpc:mainfrom
dongjiang1989:fix-sync-close

Conversation

@dongjiang1989

Copy link
Copy Markdown
Contributor

Summary

  • close() now calls the underlying HTTP client's close()/aclose() to release connection pool resources (with graceful fallback when the method is not available on the HTTP client)
  • All execute_* methods now raise RuntimeError when called on a closed client
  • _consume_single_response ensures stream.aclose() is called in a finally block to prevent async generator resource leaks
  • Extracted _check_closed() helper to avoid duplication across execute methods

Test plan

  • New unit tests in test/test_client_close.py covering all three fixes (13 tests)
  • Existing test suite passes (231 passed, 2 pre-existing unrelated failures in test_example.py)

@anuraaga

Copy link
Copy Markdown
Collaborator

Thanks @dongjiang1989 - some questions

Comment thread src/connectrpc/_client_async.py Outdated
Comment thread src/connectrpc/_client_async.py Outdated
dongjiang1989 added a commit to dongjiang1989/connect-py that referenced this pull request Jul 13, 2026
- Remove HTTP client close logic: the underlying HTTP client may be
  shared (default shared client or user-provided), so we should not
  close it. Just mark the connect client as closed.
- Remove stream.aclose() from _consume_single_response: the generator
  is a private implementation detail and cleanup is handled elsewhere.
- Fix EM101: extract RuntimeError message to variable.
- Update tests to match new behavior.

Addresses review comments on PR connectrpc#298.

Signed-off-by: dongjiang <dongjiang1989@126.com>
dongjiang1989 added a commit to dongjiang1989/connect-py that referenced this pull request Jul 13, 2026
The connect client's close() method only marks the client as closed.
Users who provide their own HTTP client are responsible for closing
it themselves. Add documentation and examples to clarify this.

Addresses review feedback on PR connectrpc#298.

Signed-off-by: dongjiang <dongjiang1989@126.com>
The connect client's close() method only marks the client as closed.
Users who provide their own HTTP client are responsible for closing
it themselves. Add documentation and examples to clarify this.

Addresses review feedback on PR connectrpc#298.

Signed-off-by: dongjiang <dongjiang1989@126.com>
dongjiang1989 and others added 2 commits July 13, 2026 17:05
Signed-off-by: dongjiang <dongjiang1989@126.com>
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
@anuraaga anuraaga changed the title Fix client resource leaks and post-close behavior Add note about http client ownership to client docs Jul 14, 2026
@anuraaga anuraaga changed the title Add note about http client ownership to client docs Add note about http client ownership to client docstrings Jul 14, 2026
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
@anuraaga

Copy link
Copy Markdown
Collaborator

Thanks @dongjiang1989 - I have moved the docs to the constructor and used context manager

dongjiang1989 added a commit to dongjiang1989/connect-py that referenced this pull request Jul 14, 2026
The connect client's close() method only marks the client as closed.
Users who provide their own HTTP client are responsible for closing
it themselves. Add documentation and examples to clarify this.

Addresses review feedback on PR connectrpc#298.

Signed-off-by: dongjiang <dongjiang1989@126.com>
@dongjiang1989

Copy link
Copy Markdown
Contributor Author

Thanks @anuraaga

@anuraaga

Copy link
Copy Markdown
Collaborator

@dongjiang1989 Please don't force-push after I've cleaned up / approved. I restored to my state and will merge after CI again

@dongjiang1989

Copy link
Copy Markdown
Contributor Author

@dongjiang1989 Please don't force-push after I've cleaned up / approved. I restored to my state and will merge after CI again

Got it.

@anuraaga
anuraaga merged commit d89c3e2 into connectrpc:main Jul 14, 2026
44 checks passed
@anuraaga

Copy link
Copy Markdown
Collaborator

Thanks!

@dongjiang1989
dongjiang1989 deleted the fix-sync-close branch July 14, 2026 02:24
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.

2 participants