Repository navigation
Conversation
… to prevent resource leaks
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
rissson
approved these changes
Jul 14, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24023 +/- ##
==========================================
- Coverage 93.31% 93.26% -0.06%
==========================================
Files 1045 1045
Lines 61401 61401
Branches 424 424
==========================================
- Hits 57296 57265 -31
- Misses 4105 4136 +31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Contributor
|
🍒 Cherry-pick to |
Contributor
|
🍒 Cherry-pick to |
BeryJu
pushed a commit
that referenced
this pull request
Jul 14, 2026
…onnections (cherry-pick #24023 to version-2026.2) (#24034) packages/django-dramatiq-postgres/broker: close unusable PostgreSQL connections (#24023) fix: close unusable PostgreSQL connection wrappers in dramatiq broker to prevent resource leaks Co-authored-by: Hassan Rady <[email protected]>
BeryJu
pushed a commit
that referenced
this pull request
Jul 14, 2026
…onnections (cherry-pick #24023 to version-2026.5) (#24035) packages/django-dramatiq-postgres/broker: close unusable PostgreSQL connections (#24023) fix: close unusable PostgreSQL connection wrappers in dramatiq broker to prevent resource leaks Co-authored-by: Hassan Rady <[email protected]>
kensternberg-authentik
added a commit
that referenced
this pull request
Jul 15, 2026
* main: web/flow: revert locale-driven flow re-request from FlowExecutor (#24050) web/bug: harmonize and make routine the display of tasks (part 3: problem children) (#23840) root: PostgreSQL direct-endpoint support for LISTEN/NOTIFY and advisory locks (#23013) docs/social-logins: Add jumpcloud oidc and saml (#24048) core, web: update translations (#24037) web: bump @goauthentik/eslint-config from 2.0.0 to 2.0.2 in /web in the goauthentik group across 1 directory (#24007) ci: bump taiki-e/install-action from 2.82.9 to 2.83.2 in /.github/actions/setup (#24045) website: bump openapi-to-postmanv2 from 6.2.0 to 6.3.0 in /website (#24041) core: bump pnpm/pnpm from 11.11.0 to 11.12.0 in /lifecycle/container (#24042) core: bump pnpm/pnpm from 11.11.0 to 11.12.0 in /website (#24043) web: bump @sentry/browser from 10.63.0 to 10.64.0 in /web in the sentry group across 1 directory (#24044) web: bump aws-cdk from 2.1128.1 to 2.1129.0 (#24046) stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#24039) packages/django-dramatiq-postgres/broker: close unusable PostgreSQL connections (#24023) api/search: add number and boolean support in AKQL queries on JSON fields (#23418) (#24028) enterprise: simplify tests (#18404) website/docs: Remove Public Release Docs. (#24031) website/docs: sys-mgmt: tweak settings wording (#24029) website/docs: cleanup 07-12: update release process guidance (#23970) website/integrations: add infiscal (#23996)
kensternberg-authentik
added a commit
that referenced
this pull request
Jul 15, 2026
* main: (104 commits) web/flow: revert locale-driven flow re-request from FlowExecutor (#24050) web/bug: harmonize and make routine the display of tasks (part 3: problem children) (#23840) root: PostgreSQL direct-endpoint support for LISTEN/NOTIFY and advisory locks (#23013) docs/social-logins: Add jumpcloud oidc and saml (#24048) core, web: update translations (#24037) web: bump @goauthentik/eslint-config from 2.0.0 to 2.0.2 in /web in the goauthentik group across 1 directory (#24007) ci: bump taiki-e/install-action from 2.82.9 to 2.83.2 in /.github/actions/setup (#24045) website: bump openapi-to-postmanv2 from 6.2.0 to 6.3.0 in /website (#24041) core: bump pnpm/pnpm from 11.11.0 to 11.12.0 in /lifecycle/container (#24042) core: bump pnpm/pnpm from 11.11.0 to 11.12.0 in /website (#24043) web: bump @sentry/browser from 10.63.0 to 10.64.0 in /web in the sentry group across 1 directory (#24044) web: bump aws-cdk from 2.1128.1 to 2.1129.0 (#24046) stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#24039) packages/django-dramatiq-postgres/broker: close unusable PostgreSQL connections (#24023) api/search: add number and boolean support in AKQL queries on JSON fields (#23418) (#24028) enterprise: simplify tests (#18404) website/docs: Remove Public Release Docs. (#24031) website/docs: sys-mgmt: tweak settings wording (#24029) website/docs: cleanup 07-12: update release process guidance (#23970) website/integrations: add infiscal (#23996) ...
kensternberg-authentik
added a commit
that referenced
this pull request
Jul 15, 2026
…card-2 * web/cleanup/schedule-card-1: (104 commits) web/flow: revert locale-driven flow re-request from FlowExecutor (#24050) web/bug: harmonize and make routine the display of tasks (part 3: problem children) (#23840) root: PostgreSQL direct-endpoint support for LISTEN/NOTIFY and advisory locks (#23013) docs/social-logins: Add jumpcloud oidc and saml (#24048) core, web: update translations (#24037) web: bump @goauthentik/eslint-config from 2.0.0 to 2.0.2 in /web in the goauthentik group across 1 directory (#24007) ci: bump taiki-e/install-action from 2.82.9 to 2.83.2 in /.github/actions/setup (#24045) website: bump openapi-to-postmanv2 from 6.2.0 to 6.3.0 in /website (#24041) core: bump pnpm/pnpm from 11.11.0 to 11.12.0 in /lifecycle/container (#24042) core: bump pnpm/pnpm from 11.11.0 to 11.12.0 in /website (#24043) web: bump @sentry/browser from 10.63.0 to 10.64.0 in /web in the sentry group across 1 directory (#24044) web: bump aws-cdk from 2.1128.1 to 2.1129.0 (#24046) stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#24039) packages/django-dramatiq-postgres/broker: close unusable PostgreSQL connections (#24023) api/search: add number and boolean support in AKQL queries on JSON fields (#23418) (#24028) enterprise: simplify tests (#18404) website/docs: Remove Public Release Docs. (#24031) website/docs: sys-mgmt: tweak settings wording (#24029) website/docs: cleanup 07-12: update release process guidance (#23970) website/integrations: add infiscal (#23996) ...
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
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.
Details
What does this PR change?
This PR modifies the locks_connection and listen_connection properties in _PostgresConsumer to explicitly call .close() on their previous, unusable connection wrappers before instantiating new connection instances via connections.create_connection(self.db_alias). It also updates exception handling in the properties to specifically catch DATABASE_ERRORS rather than using blind/broad Exception catching, complying with Python linting best practices.
Why is this change needed?
In django-dramatiq-postgres, _PostgresConsumer instantiates dedicated connection wrappers for handling advisory locks and notifications via connections.create_connection(self.db_alias). Because these connection objects are created dynamically and are not managed in Django's central thread-local/context-local connection registry (connections._connections), they are invisible to standard lifecycle hooks and cleanup operations like connections.close_all().
When a connection fails the .is_usable() check:
The property getter re-instantiates a new connection and overwrites the instance reference.
The old connection wrapper is orphaned in memory without first being closed.
This leaks the client-side TCP sockets and database file descriptors until Python's garbage collection runs.
During database reconnect storms, failovers, or network partitioning, this leaks connections linearly, exhausting PostgreSQL connection limits (OperationalError: FATAL: remaining connection slots are reserved for non-replication superuser connections) and causing a Denial of Service (DoS) for the entire application.
In addition, orphaned connections keep their advisory locks active on the PostgreSQL server, blocking other healthy worker nodes from reclaiming/executing those tasks until TCP/GC timeout occurs.
Explicitly calling .close() on the discarded wrappers frees client-side socket/FD resources instantly and forces PostgreSQL to drop the session and release its locks immediately.
How was this tested?
Validated via codebase review of connection registry mechanics.
Verified file formatting and linting rules pass using black and ruff (ensuring catching DATABASE_ERRORS satisfies BLE001).
Linked issues
#24022
Checklist
make all)make docs)