Skip to content

Avoid redundant _release_connection calls#12221

Open
rodrigobnogueira wants to merge 1 commit intoaio-libs:masterfrom
rodrigobnogueira:bugfix/10089-release-connection-once
Open

Avoid redundant _release_connection calls#12221
rodrigobnogueira wants to merge 1 commit intoaio-libs:masterfrom
rodrigobnogueira:bugfix/10089-release-connection-once

Conversation

@rodrigobnogueira
Copy link
Member

What do these changes do?

This change removes redundant ClientResponse._release_connection() invocations on successful request paths.

  • ClientResponse.release() now calls _release_connection() only when _connection is still present.
  • ClientResponse._wait_released() now does the same guard.
  • ClientResponse.wait_for_close() no longer calls release() a second time when already released.
  • Added regression test test_release_connection_called_once_per_request.
  • Added changelog fragment CHANGES/10089.bugfix.rst.

Are there changes in behavior for the user?

Yes, internal behavior changed: a successful request now executes one release-path call per response instead of repeated no-op release calls. Connection reuse/cleanup semantics are preserved.

Is it a substantial burden for the maintainers to support this?

No. The change is small, localized, and covered by regression + existing suite coverage.

Related issue number

Fixes #10089

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Mar 10, 2026
@rodrigobnogueira rodrigobnogueira force-pushed the bugfix/10089-release-connection-once branch from 2be3b22 to a68aac5 Compare March 10, 2026 03:29
@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.11%. Comparing base (8663d2a) to head (0a29170).
⚠️ Report is 4 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12221   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files         130      130           
  Lines       45324    45361   +37     
  Branches     2392     2396    +4     
=======================================
+ Hits        44921    44958   +37     
  Misses        271      271           
  Partials      132      132           
Flag Coverage Δ
CI-GHA 98.97% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.71% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.97% <100.00%> (-0.01%) ⬇️
OS-macOS 97.86% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.41% <100.00%> (+<0.01%) ⬆️
Py-3.10.19 97.89% <100.00%> (+<0.01%) ⬆️
Py-3.11.14 98.09% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.61% <100.00%> (-0.01%) ⬇️
Py-3.12.10 97.70% <100.00%> (-0.01%) ⬇️
Py-3.12.12 98.18% <100.00%> (+<0.01%) ⬆️
Py-3.13.12 98.43% <100.00%> (+<0.01%) ⬆️
Py-3.14.3 98.49% <100.00%> (-0.01%) ⬇️
Py-3.14.3t 97.49% <100.00%> (+0.01%) ⬆️
Py-pypy3.11.13-7.3.20 97.52% <100.00%> (+<0.01%) ⬆️
VM-macos 97.86% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.71% <100.00%> (+<0.01%) ⬆️
VM-windows 96.97% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 10, 2026

Merging this PR will not alter performance

✅ 59 untouched benchmarks


Comparing rodrigobnogueira:bugfix/10089-release-connection-once (0a29170) with master (8663d2a)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (92fa5ef) during the generation of this report, so 8663d2a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@rodrigobnogueira rodrigobnogueira force-pushed the bugfix/10089-release-connection-once branch from 819d985 to a09c0e2 Compare March 10, 2026 11:22

self._cleanup_writer()
self._release_connection()
if self._connection is not None:
Copy link
Member

Choose a reason for hiding this comment

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

This check already happens inside _release_connection(). Is it the function call itself that's adding too much overhead? I'll leave @bdraco to review this one.

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

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_release_connection is always called 4x on a successful request

2 participants