Skip to content

837 backend pg pool created without max idle connection statement timeout settings - #1175

Merged
ogazboiz merged 6 commits into
LabsCrypt:mainfrom
jotel-dev:837-backend-pg-pool-created-without-max-idle-connection-statement-timeout-settings
Aug 8, 2026
Merged

837 backend pg pool created without max idle connection statement timeout settings#1175
ogazboiz merged 6 commits into
LabsCrypt:mainfrom
jotel-dev:837-backend-pg-pool-created-without-max-idle-connection-statement-timeout-settings

Conversation

@jotel-dev

Copy link
Copy Markdown
Contributor

Description

This PR addresses issue #837 by ensuring pg.Pool is constructed with environment-configurable settings for maximum pool size, connection timeouts, idle timeouts, and statement execution timeouts. Previously, pg.Pool was instantiated with no explicit tuning, using node-postgres defaults (max 10 connections, no statement timeout), which risked connection pool exhaustion and unbound slow query execution under load.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ⚡ Performance improvement
  • 📚 Documentation update
  • 🧪 Test addition or update

Related Issues

Closes #837

Changes Made

  • backend/src/lib/pg-pool.ts:
    • Implemented createPgPoolConfig with sane default fallbacks:
      • PG_POOL_MAX: 10
      • PG_IDLE_TIMEOUT_MS: 30000 (30s)
      • PG_CONNECTION_TIMEOUT_MS: 5000 (5s)
      • PG_STATEMENT_TIMEOUT_MS: 30000 (30s)
    • Updated createPgPoolConfig and createPgPool to accept optional Partial<pg.PoolConfig> overrides.
  • backend/.env.example:
    • Documented all 4 PostgreSQL pool environment variables with comments and default values.
  • backend/src/lib/prisma.ts & backend/prisma/seed.ts:
    • Ensured pool instantiation uses createPgPool().
  • backend/tests/pg-pool.test.ts & backend/tests/integration/stream-lifecycle.test.ts:
    • Added unit test cases covering configuration defaults, environment variable overrides, invalid input fallbacks, and custom pool overrides.
    • Updated integration tests to initialize database pools via createPgPool({ connectionString }).

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Steps

  1. Run backend unit tests: npm test from backend/ directory. All 51 test files pass, and pg-pool.ts reaches 100% test coverage.
  2. Verify env variable overrides by setting PG_POOL_MAX=25, PG_STATEMENT_TIMEOUT_MS=15000, etc., in .env and running createPgPoolConfig().
  3. Verify invalid env variable fallbacks (e.g. PG_POOL_MAX=invalid falls back to default 10).

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have checked for breaking changes and documented them if applicable

…timeouts (LabsCrypt#837)

- Support env configuration for PG_POOL_MAX, PG_IDLE_TIMEOUT_MS, PG_CONNECTION_TIMEOUT_MS, PG_STATEMENT_TIMEOUT_MS in createPgPoolConfig with sane defaults
- Document pool settings in backend/.env.example
- Accept optional config overrides in createPgPool
- Expand unit tests for default, custom env, invalid inputs, and overrides
@ogazboiz
ogazboiz merged commit 8723543 into LabsCrypt:main Aug 8, 2026
10 checks passed
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.

[Backend] pg.Pool created without max / idle / connection / statement timeout settings

2 participants