镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Fix own_client so close() closes the client created internally - #284

Merged
HardNorth merged 1 commit into
reportportal:developfrom
BlueX888:contrib/own-client-close
Nov 9, 2026
Merged

HardNorth merged 1 commit into
reportportal:developfrom
BlueX888:contrib/own-client-close

Conversation

@BlueX888

@BlueX888 BlueX888 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #283

The else branch of _RPClient.__init__ creates its own Client but sets own_client = False, so close() skips self.__client.close() and the aiohttp session stays open until garbage collection warns about it. Set the flag to True in that branch; a client passed via client= remains borrowed and is still not closed.

Client.__setstate__ also restores _session = None, because __getstate__ removes it and unpickling left the attribute missing. Without this, the newly-enabled close() path on an unpickled wrapper raised AttributeError, and an unpickled Client also failed on its first session() call.

Regression tests:

  • tests/aio/test_batched_client.py::test_own_client_reflects_client_ownership (parametrized over BatchedRPClient and ThreadedRPClient) asserts own_client is True for an internally-created client and False for an injected one. Both params fail on develop with assert False is True.
  • test_batched_rp_client_pickling now checks the unpickled wrapper owns its client and that close() succeeds.

Full suite: 418 passed, 2 pre-existing network/port failures (tests/_internal/aio/test_aio_http.py::test_no_retry_on_ok_request — OSError: [Errno 48] Address already in use; tests/_internal/test_http.py::test_no_auth_request — requests.exceptions.ConnectionError). Both also fail on the unmodified base.

@HardNorth HardNorth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HardNorth
HardNorth merged commit 8b6a856 into reportportal:develop Nov 9, 2026
0 of 7 checks passed
@BlueX888

BlueX888 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

The only failed job is build (3.9): actions/setup-python reports The version '3.9' with architecture 'x64' was not found for Ubuntu 26.04, and the other six jobs were cancelled by fail-fast. The change is plain pytest and does not depend on the interpreter version, so this looks like the runner image no longer carrying 3.9 rather than the patch. Thanks for the LGTM.

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.

Async RPClient doesn't close client session

2 participants