# Database connection pool exhausted

Classification: environment
Frameworks: CI, Jest, pytest
Canonical: https://automationtester.in/failures/database-pool-exhausted

## Recognizable error

```text
Timed out fetching a new connection from the connection pool
```

## What it means

Concurrent test work requested more database connections than the configured pool could provide before its timeout.

## Ranked causes, checks, and fixes

### 1. Each test creates a new client

Clients are opened repeatedly and not reused or closed.

Diagnostic: Count client construction and active connections per worker.

Fix: Create one lifecycle-managed client per worker and close it after the suite.

### 2. Worker concurrency exceeds the database budget

Parallel processes multiply each client's pool size.

Diagnostic: Calculate workers multiplied by pool maximum and compare it with the server limit.

Fix: Reduce per-worker pool size or test concurrency while preserving isolation.

### 3. Transactions or streams leak connections

An error path may skip release or rollback.

Diagnostic: Inspect long-running sessions and unclosed transaction paths.

Fix: Use scoped helpers that release in finally blocks.

## Prevention

- Budget connections across workers.
- Manage clients at worker scope.
- Assert cleanup on failure paths.

## Primary references

- [Prisma connection pool](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/databases-connections/connection-pool)

Triage this failure locally: https://automationtester.in/tools/test-failure-triage