Skip to content

packages/ak-common/db: reuse connections briefly when conn_max_age is 0 - #28406

Draft
dewi-tik wants to merge 1 commit into
mainfrom
packages/ak-common/db-reuse-connections
Draft

dewi-tik wants to merge 1 commit into
mainfrom
packages/ak-common/db-reuse-connections

Conversation

@dewi-tik

@dewi-tik dewi-tik commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

When postgresql.conn_max_age is 0 (the default), the Rust connection pool now keeps idle connections for 5 seconds instead of closing each one on release. It holds no minimum connection and checks a connection before reusing it. The pool is still capped at 4 connections.

Why is this change needed?

The embedded proxy outpost loads the session from PostgreSQL on every authenticated request. With close-on-release, each forward-auth or proxied request opened a new connection (connect, auth, SET, query, close).

Measured locally on a release build with PostgreSQL 18 and password auth, on an authenticated /outpost.goauthentik.io/auth/nginx request:

Before After
Single request ~7 ms 0.9 ms
8 concurrent clients 175 req/s ~4,800 req/s

The close-on-release behavior came from #22679, which fixed a pool spin. This change doesn't bring the spin back. Idle CPU stayed flat and pooled connections were gone after the idle timeout.

How was this tested?

  • Killed the pooled backends with pg_terminate_backend; the following requests all returned 200. Without test_before_acquire, the first one returned 401.

Linked issues

refs #22679


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)
  • I have read the AI usage policy.

With conn_max_age set to 0, the default, the pool closed every connection
on release. The embedded proxy outpost loads the session from PostgreSQL on
each authenticated request, so every request opened a new connection.

Keep idle connections for 5 seconds instead, hold no minimum, and check a
connection before reusing it.
@dewi-tik dewi-tik self-assigned this Dec 2, 2026
@netlify

netlify Bot commented Dec 2, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 0404e96
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6b100799071a07fcca877468
😎 Deploy Preview https://deploy-preview-28406--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.77%. Comparing base (3931139) to head (0404e96).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #28406      +/-   ##
==========================================
- Coverage   93.80%   93.77%   -0.03%     
==========================================
  Files        1262     1262              
  Lines       91705    91705              
  Branches     5752     5752              
==========================================
- Hits        86023    85997      -26     
- Misses       5596     5622      +26     
  Partials       86       86              
Flag Coverage Δ
conformance 29.20% <ø> (+<0.01%) ⬆️
e2e 33.63% <ø> (+<0.01%) ⬆️
integration 26.55% <ø> (-0.30%) ⬇️
rust 62.37% <ø> (ø)
unit 94.99% <ø> (-0.01%) ⬇️
unit-migrate 95.00% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Playwright e2e

Download this run's HTML report and traces, then open the report:

gh run download 46876271709 -D playwright-artifacts
npx playwright show-report playwright-artifacts/playwright-report

Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-0404e96e91dd6669e266f7434a54d9b9b586a326
# Distroless image: AUTHENTIK_TAG=gh-0404e96e91dd6669e266f7434a54d9b9b586a326-distroless
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
    image:
        repository: ghcr.io/goauthentik/dev-server
        tag: gh-0404e96e91dd6669e266f7434a54d9b9b586a326
        # Distroless image: tag: gh-0404e96e91dd6669e266f7434a54d9b9b586a326-distroless

Afterwards, run the upgrade commands from the latest release notes.

This branch has not been deployed

No deployments
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