Skip to content

[PR #11074/e550c78a backport][3.12] Fix connector not waiting for connections to close #11077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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.12] [PR #3733/6b0bc4ef backport][3.13] Fix connector not waiting for connections to close [PR #11074/e550c78a backport][3.12] Fix connector not waiting for connections to close May 29, 2025
@bdraco bdraco enabled auto-merge (squash) May 29, 2025 00:13
Copy link

codspeed-hq bot commented May 29, 2025

CodSpeed Performance Report

Merging #11077 will not alter performance

Comparing patchback/backports/3.12/e550c78a943be34ffd01b58acbcc0f06485bbbd9/pr-11074 (016f478) with 3.12 (3df3ab5)

Summary

✅ 59 untouched benchmarks

Copy link

codecov bot commented May 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.24%. Comparing base (2002b9d) to head (016f478).
Report is 1 commits behind head on 3.12.

Additional details and impacted files
@@           Coverage Diff           @@
##             3.12   #11077   +/-   ##
=======================================
  Coverage   98.24%   98.24%           
=======================================
  Files         130      130           
  Lines       41612    41664   +52     
  Branches     2286     2291    +5     
=======================================
+ Hits        40881    40933   +52     
  Misses        557      557           
  Partials      174      174           
Flag Coverage Δ
CI-GHA 98.13% <98.82%> (-0.01%) ⬇️
OS-Linux 97.87% <98.82%> (-0.01%) ⬇️
OS-Windows 95.47% <98.82%> (-0.01%) ⬇️
OS-macOS 97.08% <98.82%> (+<0.01%) ⬆️
Py-3.10.11 96.97% <97.64%> (+<0.01%) ⬆️
Py-3.10.17 97.48% <97.64%> (+<0.01%) ⬆️
Py-3.11.12 97.53% <97.64%> (-0.02%) ⬇️
Py-3.11.9 97.05% <97.64%> (-0.01%) ⬇️
Py-3.12.10 97.92% <97.64%> (-0.01%) ⬇️
Py-3.13.3 97.91% <97.64%> (+<0.01%) ⬆️
Py-3.9.13 96.86% <97.64%> (+<0.01%) ⬆️
Py-3.9.22 97.37% <97.64%> (-0.02%) ⬇️
Py-pypy7.3.16 88.48% <97.64%> (+2.23%) ⬆️
VM-macos 97.08% <98.82%> (+<0.01%) ⬆️
VM-ubuntu 97.87% <98.82%> (-0.01%) ⬇️
VM-windows 95.47% <98.82%> (-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.

@bdraco bdraco merged commit 0abffd5 into 3.12 May 29, 2025
35 checks passed
@bdraco bdraco deleted the patchback/backports/3.12/e550c78a943be34ffd01b58acbcc0f06485bbbd9/pr-11074 branch May 29, 2025 00: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.

1 participant