Skip to content

Conversation

patchback[bot]
Copy link
Contributor

@patchback patchback bot commented May 29, 2025

This is a backport of PR #11074 as merged into 3.13 (e550c78).

What do these changes do?

This PR fixes an issue where BaseConnector.close() would return immediately without waiting for connections to actually close. This is a partial backport of #3733 that includes only the bug fix without any breaking API changes.

The fix ensures that close() properly waits for all connection closures to complete by:

  • Collecting all proto.closed futures from connections being closed
  • Using asyncio.gather() to wait for all closures to complete
  • Optimizing for Python 3.12+ by using eager task execution when available

Are there changes in behavior for the user?

No breaking changes. The close() method will now properly wait for connections to close as expected, which is the correct behavior. The method continues to return an awaitable that emits a deprecation warning if not awaited.

Note: When using the connector as a non-async context manager (deprecated pattern), the issue of not waiting for connections to close still remains. This is because __exit__ calls _close() synchronously and cannot await the connection closures. Users should use the async context manager pattern (async with) instead. We cannot remove the sync context manager in 3.x as that would be a breaking change.

Related issue number

Partial backport of #3733
fixes #1925 fixes #3736

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/ folde

…ections to close (#11074)

fixes #1925 fixes #3736

(cherry picked from commit e550c78)
@patchback patchback bot requested review from webknjaz and asvetlov as code owners May 29, 2025 00:02
@bdraco bdraco changed the title [PR #11074/e550c78a backport][3.11] [PR #3733/6b0bc4ef backport][3.13] Fix connector not waiting for connections to close [PR #11074/e550c78a backport][3.11] Fix connector not waiting for connections to close May 29, 2025
Copy link

codspeed-hq bot commented May 29, 2025

CodSpeed Performance Report

Merging #11076 will not alter performance

Comparing patchback/backports/3.11/e550c78a943be34ffd01b58acbcc0f06485bbbd9/pr-11074 (6c4447d) with 3.11 (145658f)

Summary

✅ 55 untouched benchmarks

@bdraco bdraco enabled auto-merge (squash) May 29, 2025 00:13
Copy link

codecov bot commented May 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.08%. Comparing base (145658f) to head (6c4447d).
⚠️ Report is 2 commits behind head on 3.11.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             3.11   #11076      +/-   ##
==========================================
+ Coverage   96.88%   98.08%   +1.19%     
==========================================
  Files         124      126       +2     
  Lines       37770    37887     +117     
  Branches     4559     4580      +21     
==========================================
+ Hits        36595    37163     +568     
+ Misses        979      546     -433     
+ Partials      196      178      -18     
Flag Coverage Δ
CI-GHA 97.97% <98.82%> (+1.16%) ⬆️
OS-Linux 97.67% <98.82%> (?)
OS-Windows 94.66% <98.82%> (?)
OS-macOS 96.80% <98.82%> (-0.01%) ⬇️
Py-3.10.11 96.68% <97.64%> (+0.29%) ⬆️
Py-3.10.17 97.22% <97.64%> (?)
Py-3.11.12 97.25% <97.64%> (?)
Py-3.11.9 96.73% <97.64%> (?)
Py-3.12.10 97.70% <97.64%> (?)
Py-3.13.3 97.73% <97.64%> (+1.14%) ⬆️
Py-3.9.13 96.58% <97.64%> (+0.29%) ⬆️
Py-3.9.22 97.09% <97.64%> (?)
Py-pypy7.3.16 96.65% <97.64%> (?)
VM-macos 96.80% <98.82%> (-0.01%) ⬇️
VM-ubuntu 97.67% <98.82%> (?)
VM-windows 94.66% <98.82%> (?)

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.

@bdraco bdraco merged commit 9f6c54d into 3.11 May 29, 2025
36 checks passed
@bdraco bdraco deleted the patchback/backports/3.11/e550c78a943be34ffd01b58acbcc0f06485bbbd9/pr-11074 branch May 29, 2025 00:19
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.

1 participant