Repository navigation
root: PostgreSQL direct-endpoint support for LISTEN/NOTIFY and advisory locks - #23013
Conversation
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-storybook 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. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23013 +/- ##
==========================================
- Coverage 92.69% 92.68% -0.01%
==========================================
Files 1045 1047 +2
Lines 61414 61637 +223
Branches 424 424
==========================================
+ Hits 56927 57129 +202
- Misses 4487 4508 +21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
5b1bc10 to
b1c2ae3
Compare
|
Yes! In principle I agree and want this change to make it in, but I have a bit of thinking to do about how this will affect future plans of moving this stuff out of Python. Also, I don't see this affecting advisory locks everywhere, like where we use |
@rissson Good point about pglock. I just pushed a commit that I think covers all of that now. |
|
Thanks! I'll take care of implementing this in |
Signed-off-by: Marc 'risson' Schmitt <[email protected]>
Signed-off-by: Marc 'risson' Schmitt <[email protected]>
|
@ryanpesek do you think it makes sense to force migrations to go through the direct connection if configured? |
That seems like the safest option to me as that would avoid any |
Signed-off-by: Marc 'risson' Schmitt <[email protected]>
* 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)
* 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) ...
…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) ...
…card-3-problem-children * web/cleanup/schedule-card-2: (113 commits) website/docs: release notes for 2026.5.5 (#24070) website/docs: release notes for 2026.2.6 (#24069) web, locale: Normalize legacy locale file names (#24024) web/bug: harmonize and make routine the display of tasks (part 4: schedule-list cards) (#23855) security: automated internal backport of patch 1822.sec.patch to authentik-main (#24064) security: automated internal backport of patch 1934.sec.patch to authentik-main (#24067) security: automated internal backport of patch 1887.sec.patch to authentik-main (#24065) security: automated internal backport of patch 1919.sec.patch to authentik-main (#24066) security: automated internal backport of patch 1817.sec.patch to authentik-main (#24063) 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) ...
…~30 s to be picked up Field report, Justin Davis (TN TAK): password-reset emails land late. He proposed a separate `worker-email` container running a custom poller over `authentik_tasks_task`. The symptom is real; the cause is not email-specific. Since v0.9.23 `_ensure_authentik_pgbouncer()` put the server AND the worker behind PgBouncer in transaction mode. Authentik 2026.x's task broker (django-dramatiq-postgres) needs LISTEN on `authentik.tasks.default.enqueue` and a session advisory lock per message, and PgBouncer lists both as "Never" under transaction pooling (https://www.pgbouncer.org/features.html). So the worker only found work on its CONSUMER_LISTEN_TIMEOUT fallback poll (30 s), and each unlock landed on a different pooled backend than its lock and leaked it. Measured from authentik_tasks_tasklog ("queued" -> "being processed"), empty queues: test6/test8/test12 (2026.5.6), nuc (2026.8.2, Rocky non-root): p50 17-30 s for every actor; 513-1123 "you don't own a lock" Postgres warnings per box per day. Worker alone pointed at Postgres on test12: 0.08-1.5 s pickup, 0 lock warnings (33 the hour before), worker connections flat at 5-7 over the soak. - `_ensure_authentik_worker_direct_pg()` (new): on the bundled topology only, moves the WORKER's AUTHENTIK_POSTGRESQL__HOST to `postgresql`, recreates the worker alone under the compose lock, verifies the live container, rolls back on failure. Runs after the pgbouncer step at deploy and on every console boot, so existing boxes get it from a console update. The server stays on PgBouncer: the #20714 leak it caps lives in the server's gunicorn workers. - `_ensure_authentik_pgbouncer()`: "wired" now means the SERVER is on pgbouncer. Requiring the worker there too would flip it back and recreate server+worker on every boot. - `_authentik_pgbouncer_pg_activity_breakdown()`: the worker's connections are `worker_direct`, so a fresh install whose server is still booting is not logged "bypassed". Upstream's proper fix is goauthentik/authentik#23013 (2026.8.0+, AUTHENTIK_POSTGRESQL__DIRECT__*), which also covers the server's Channels LISTEN; filed to ROADMAP for the 2026.8 vetting. Validated: local harness on real test8/test12 compose files, 39/39 (existing box, second-boot no-op, pgbouncer gate no-op, exited-worker rollback, fresh install, external PG, absent); the old gate fails 7 of them. pre-merge-check clean apart from the pre-existing oversize_files ratchet; redteam-selfaudit no regressions. Not yet T&E'd. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Why
authentik has three subsystems that hold state on a single PostgreSQL
backend across multiple statements: the Channels Postgres layer (LISTEN
on a long-lived connection), the dramatiq worker (LISTEN + session-scoped
pg_advisory_lock), and the startup migration'spg_advisory_lock(1000).Behind a transaction-pooling pooler (PgBouncer
pool_mode=transaction,Cloud SQL managed pooling) all three break silently — the pooler returns
the backend to the pool at every COMMIT, severing the LISTEN registration
and releasing the lock without anyone telling the app.
This blocks deployments from using a transaction-mode pooler in front of
authentik at all, even though such a pooler is the standard way to deal
with PG connection exhaustion in production. Today operators run direct
connections from every app thread, hitting the
max_connectionsceilingunder load.
What
Adds an optional
postgresql.direct.*config block. When set, a Djangodatabase alias named
directis added; the three session-stablesubsystems route through it while ORM traffic continues through the
defaultalias (which can now safely point at a transaction-poolingpooler).
Safety
Opt-in. When
postgresql.direct.*is unset,postgresql_direct_db_enabled()returns False, no Django alias is added, and all subsystems use
defaultas before. Identical behavior to the current codebase.
Checklist
make all)make docs)