-
Notifications
You must be signed in to change notification settings - Fork 435
Avoid leaking connections if _can_use_connection fails #1269
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
elprans
approved these changes
Oct 11, 2025
Member
elprans
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks for the fix!
elprans
added a commit
that referenced
this pull request
Nov 24, 2025
Enable Python 3.14 with experimental subinterpreter/freethreading support. Improvements ============ * Add Python 3.14 support, experimental subinterpreter/freethreading support (#1279) (by @elprans in 9e42642) * Avoid performing type introspection on known types (#1243) (by @elprans in 5c9986c) * Make `prepare()` not use named statements by default when cache is disabled (#1245) (by @elprans in 5b14653) * Implement connection service file functionality (#1223) (by @AndrewJackson2020 in 1d63bb1) Fixes ===== * Fix multi port connection string issue (#1222) (by @AndrewJackson2020 in 01c0db7) * Avoid leaking connections if _can_use_connection fails (#1269) (by @yuliy-openai in e94302d) Other ===== * Drop support for EOL Python 3.8 (#1281) (by @elprans in 6c2c490)
Merged
1 task
bg-admin7
pushed a commit
to bg-open-source/asyncpg
that referenced
this pull request
Dec 10, 2025
asyncpg v0.31.0 Enable Python 3.14 with experimental subinterpreter/freethreading support. Improvements ============ * Add Python 3.14 support, experimental subinterpreter/freethreading support (MagicStack#1279) (by @elprans in 9e42642) * Avoid performing type introspection on known types (MagicStack#1243) (by @elprans in 5c9986c) * Make `prepare()` not use named statements by default when cache is disabled (MagicStack#1245) (by @elprans in 5b14653) * Implement connection service file functionality (MagicStack#1223) (by @AndrewJackson2020 in 1d63bb1) Fixes ===== * Fix multi port connection string issue (MagicStack#1222) (by @AndrewJackson2020 in 01c0db7) * Avoid leaking connections if _can_use_connection fails (MagicStack#1269) (by @yuliy-openai in e94302d) Other ===== * Drop support for EOL Python 3.8 (MagicStack#1281) (by @elprans in 6c2c490) # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEES/rQWfT9RAppNY3YXEaHeAYth78FAmkk6UMACgkQXEaHeAYt # h7+LBw//fX/3/nHrEUctYR7A/WQqg2oj3nvk10b3OQjzHUGyHq0DhkSC7/H9P0FI # vl0j2n+BfKcKxOw4OgbxDq5fff/a4ScsejVwsKqQEEDH9tiXAL2cIId1yvNWC9hJ # 8WxmkJzbFHdrl1D3/pxUv15UoaMSZD1DtPXaYEupRyEKXVOfQ/ush5GU5M3vA19R # aWrAFtbMd3MMfaBYEO1TQtZNCV3n3Dv8fmIwv8qPbqJt2lsk4HOE8F3Be/RGiaPZ # dI9eGnZ+qmlYC/mZYKNywaBlm4v/hHhuGwSh8WdkY6h4lFkBl8HipuPpoNeWO/fd # k5wl1Q2HA8i2qEokz7EzYPRYjOPZwXphxscRXJQbdlCNyfJ+lPTu3uAQ08RTnoGU # +JROauwgtQknnZEGtRWNerRcbZE1D+SgkLhGkEk6+tcIJ0G2XoCsn7A/u9LMmZuN # 7lcFnLEdDnUSaLx7SZgcbOKP1Acg1W2Vk375JxXrymGqq5FPss8cdg+KOFMNuljT # v/RtKvAP3yXpR448uPQ6M4BNVJ5my3UwdPrHwpGNkSxaqKBGGtryBG4LLw43yPCg # FPFO9P//z+59RsmAvilaOhT/pLhqRvOJTkaUt5bt6Fw+5SzCfNfciNkl4rBC+9EQ # LC/NQmO9cFYlpnO7s3uF0M+JTLV1u0CJp5G5USiQiEU+tVlaH6E= # =bEvL # -----END PGP SIGNATURE----- # gpg: Signature made Tue 25 Nov 2025 12:24:51 AM CET # gpg: using RSA key 4BFAD059F4FD440A69358DD85C468778062D87BF # gpg: Can't check signature: No public key
bg-admin7
pushed a commit
to bg-open-source/asyncpg
that referenced
this pull request
Dec 10, 2025
asyncpg v0.31.0 Enable Python 3.14 with experimental subinterpreter/freethreading support. Improvements ============ * Add Python 3.14 support, experimental subinterpreter/freethreading support (MagicStack#1279) (by @elprans in 9e42642) * Avoid performing type introspection on known types (MagicStack#1243) (by @elprans in 5c9986c) * Make `prepare()` not use named statements by default when cache is disabled (MagicStack#1245) (by @elprans in 5b14653) * Implement connection service file functionality (MagicStack#1223) (by @AndrewJackson2020 in 1d63bb1) Fixes ===== * Fix multi port connection string issue (MagicStack#1222) (by @AndrewJackson2020 in 01c0db7) * Avoid leaking connections if _can_use_connection fails (MagicStack#1269) (by @yuliy-openai in e94302d) Other ===== * Drop support for EOL Python 3.8 (MagicStack#1281) (by @elprans in 6c2c490) # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEES/rQWfT9RAppNY3YXEaHeAYth78FAmkk6UMACgkQXEaHeAYt # h7+LBw//fX/3/nHrEUctYR7A/WQqg2oj3nvk10b3OQjzHUGyHq0DhkSC7/H9P0FI # vl0j2n+BfKcKxOw4OgbxDq5fff/a4ScsejVwsKqQEEDH9tiXAL2cIId1yvNWC9hJ # 8WxmkJzbFHdrl1D3/pxUv15UoaMSZD1DtPXaYEupRyEKXVOfQ/ush5GU5M3vA19R # aWrAFtbMd3MMfaBYEO1TQtZNCV3n3Dv8fmIwv8qPbqJt2lsk4HOE8F3Be/RGiaPZ # dI9eGnZ+qmlYC/mZYKNywaBlm4v/hHhuGwSh8WdkY6h4lFkBl8HipuPpoNeWO/fd # k5wl1Q2HA8i2qEokz7EzYPRYjOPZwXphxscRXJQbdlCNyfJ+lPTu3uAQ08RTnoGU # +JROauwgtQknnZEGtRWNerRcbZE1D+SgkLhGkEk6+tcIJ0G2XoCsn7A/u9LMmZuN # 7lcFnLEdDnUSaLx7SZgcbOKP1Acg1W2Vk375JxXrymGqq5FPss8cdg+KOFMNuljT # v/RtKvAP3yXpR448uPQ6M4BNVJ5my3UwdPrHwpGNkSxaqKBGGtryBG4LLw43yPCg # FPFO9P//z+59RsmAvilaOhT/pLhqRvOJTkaUt5bt6Fw+5SzCfNfciNkl4rBC+9EQ # LC/NQmO9cFYlpnO7s3uF0M+JTLV1u0CJp5G5USiQiEU+tVlaH6E= # =bEvL # -----END PGP SIGNATURE----- # gpg: Signature made Tue 25 Nov 2025 12:24:51 AM CET # gpg: using RSA key 4BFAD059F4FD440A69358DD85C468778062D87BF # gpg: Can't check signature: No public key
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If _can_use_connection fails (say, because of an asyncio timeout), then we may have a full connection that has been created but would be leaked by this function. (note:
_connect_addrtakes care of cleaning up after itself if it fails partway)This is particularly possible in the case of pgbouncer, where we may succeed at establishing a connection much quicker than even a trivial call to the backing database would take.
I believe this failure mode was introduced in #987
I'm not certain if we should
awaithere or just punt the closing of the other connections to a background task (I don't know how riskycloseis on an established connection).