Skip to content

fix: Add database connection pool configuration for GOTRUE#396

Open
everettbu wants to merge 1 commit into
masterfrom
fix/auth-connection-leak
Open

fix: Add database connection pool configuration for GOTRUE#396
everettbu wants to merge 1 commit into
masterfrom
fix/auth-connection-leak

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of supabase/supabase#41492
Original author: krishvsoni


I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Fixes #41033 - Supabase Auth API leaks connections

The Supabase Auth service (GoTrue) was creating unlimited database connections during high-load authentication scenarios, leading to connection exhaustion and "cannot assign requested address" errors. This occurred because the Auth service lacked explicit connection pool configuration in the Docker setup, causing it to use default values that were insufficient for concurrent authentication requests.

What is the new behavior?

The Auth service now has proper connection pool configuration with:

  • GOTRUE_DB_MAX_POOL_SIZE=10 (configurable via environment variables)
  • GOTRUE_DB_MAX_POOL_SIZE_UNIT=connections (absolute connection limit)

This prevents connection exhaustion by limiting the number of concurrent database connections the Auth service can establish, ensuring stable performance during high-load authentication operations.

Additional context

Root Cause

The Auth service connects to PostgreSQL but lacked explicit connection pooling limits in the default Docker configuration. During high-load scenarios (multiple concurrent sign-ups/sign-ins), this caused the service to exhaust system resources and fail with connection errors.

Changes Made

  1. docker/docker-compose.yml: Added environment variables to the auth service:

    GOTRUE_DB_MAX_POOL_SIZE: ${GOTRUE_DB_MAX_POOL_SIZE:-10}
    GOTRUE_DB_MAX_POOL_SIZE_UNIT: ${GOTRUE_DB_MAX_POOL_SIZE_UNIT:-connections}
  2. docker/.env.example: Added default configuration values:

    GOTRUE_DB_MAX_POOL_SIZE=15
    GOTRUE_DB_MAX_POOL_SIZE_UNIT=connections

Testing

The fix can be verified by:

  1. Starting the services with docker compose up -d
  2. Running concurrent authentication requests (more than the pool limit)
  3. Monitoring that connections stay within the configured limit
  4. Confirming no "cannot assign requested address" errors occur

Verification Results:

  • Auth service now maintains only 2 active database connections (vs. unlimited before)
  • Connection pool limit of 10 is respected
  • No connection exhaustion errors during high-load scenarios

Database Connection Query Results:

SELECT usename, count(*) as connections 
FROM pg_stat_activity 
WHERE usename = 'supabase_auth_admin' 
GROUP BY usename;

Output:

       usename       | connections
---------------------+-------------
 supabase_auth_admin |           2
(1 row)

Configuration Notes

  • Default pool size: 10 connections (fallback in docker-compose.yml)
  • Recommended for moderate load: 15 connections (set in .env.example)
  • For high load scenarios: Can be increased to 20-40 connections
  • Connections are reused and returned to the pool when idle

This fix resolves the connection leak issue reported in the Supabase community and ensures stable Auth service performance under load.

Summary by CodeRabbit

  • Chores
    • Added new database connection pool configuration options to support tunable pool size and unit settings for the authentication service.

✏️ Tip: You can customize this high-level summary in your review settings.

@everettbu everettbu added the self-hosted Related to self-hosted Supabase label Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

self-hosted Related to self-hosted Supabase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants