Skip to content

[adapter-mariadb] idleTimeout configuration ignored - connections leak in Sleep state #28964

Closed

Description

@Mimmox81

Bug description

When using @prisma/adapter-mariadb with Prisma 7, the idleTimeout configuration is completely ignored. Connections are created but never returned to the pool - they remain in MySQL "Sleep" state for 50-60+ seconds instead of being released after the configured idle timeout.

This causes connection pool exhaustion under normal load.

How to reproduce

  1. Configure Prisma 7 with MariaDB adapter:
import { PrismaClient } from '@prisma/client';
import { PrismaMariaDB } from '@prisma/adapter-mariadb';
import mariadb from 'mariadb';

const pool = mariadb.createPool({
  host: 'localhost',
  user: 'user',
  password: 'password',
  database: 'mydb',
  connectionLimit: 30,
  idleTimeout: 5000,        // 5 seconds - IGNORED
  minimumIdle: 2,
  acquireTimeout: 10000,
});

const adapter = new PrismaMariaDB(pool);
const prisma = new PrismaClient({ adapter });

2. Run any query:
await prisma.user.findMany();

3. Check MySQL connections:
SHOW PROCESSLIST;
-- or
SELECT * FROM information_schema.PROCESSLIST WHERE COMMAND = 'Sleep' AND USER = 'user';

4. Expected: Connection should be released after 5 seconds idle
5. Actual: Connection stays in Sleep state for 50-60+ seconds, accumulating with each query

Expected behavior

Connections should be returned to the pool and released according to idleTimeout configuration (5 seconds in the example above).

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

Environment & setup

- OS: Ubuntu 24.04 LTS
- Database: MariaDB 10.11.15
- Node.js: v20.x
- Prisma: 7.2.1
- @prisma/adapter-mariadb: 7.2.1
- mariadb (driver): 3.4.0

Impact

Severity: High - Production systems experience connection exhaustion

In our production environment (2 API instances × 30 connections = 60 pool limit), we observed:
- Connections accumulating to 41/40 (102% of original limit) within hours
- Queries timing out with "Connection pool timeout"
- Users experiencing 500 errors

Current Workaround

We implemented a cron-based workaround that kills leaked connections every 30 seconds:

#!/bin/bash
# Kill connections idle > 10 seconds
mysql -e "SELECT CONCAT('KILL ', ID, ';') FROM information_schema.PROCESSLIST 
          WHERE COMMAND = 'Sleep' AND USER = 'app_user' AND TIME > 10;" | mysql

This is not ideal but keeps the system operational.

Additional context

- The same configuration worked correctly with Prisma 5.x (without driver adapters)
- The mariadb npm package's idleTimeout works correctly when used directly (without Prisma adapter)
- This suggests the adapter is not properly propagating pool management to the underlying driver

Logs

Connection cleanup log showing ~15-20 leaked connections every 30 seconds:
2025-12-26 20:08:01 KILLED=20 idle connections (>10s)
2025-12-26 20:08:31 KILLED=14 idle connections (>10s)
2025-12-26 20:09:01 KILLED=20 idle connections (>10s)
2025-12-26 20:09:31 KILLED=18 idle connections (>10s)
2025-12-26 20:10:01 KILLED=16 idle connections (>10s)


### Severity

🚨 Critical: Data loss, app crash, security issue

### Reproduction

<!-- Link to CodeSandbox, GitHub repo, or step-by-step instructions -->


### Expected vs. Actual Behavior

Connections should be returned to the pool and released according to idleTimeout configuration (5 seconds in the example above).

Prisma information

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}


### Frequency

Consistently reproducible

### Does this occur in development or production?

Both development and production

### Is this a regression?

Yes it worked in Prisma 5,X and it doesn't in Prisma 7


### Workaround

We implemented a cron-based workaround that kills leaked connections every 30 seconds:

#!/bin/bash
# Kill connections idle > 10 seconds
mysql -e "SELECT CONCAT('KILL ', ID, ';') FROM information_schema.PROCESSLIST 
          WHERE COMMAND = 'Sleep' AND USER = 'app_user' AND TIME > 10;" | mysql

This is not ideal but keeps the system operational.



### Prisma Schema & Queries

```prisma
// Add relevant schema.prisma snippet
// Add relevant Prisma Client query

Prisma Config

// Add your `prisma.config.ts`

Logs & Debug Info

// Debug logs here

Environment & Setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version

// Prisma version output

Activity

  1. added
    kind/bug
    on Dec 27, 2025
  2. coderabbitai commented on Dec 27, 2025

    @coderabbitai
    Contributor

    📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    🔗 Similar Issues

    Related Issues

    🔗 Related PRs

    #28771 - fix(cli): studio mishandles remote "prisma+postgres:" connection strings. [merged]
    #28831 - fix: don't leak connections in timed out transactions [merged]
    #28883 - fix: remove pool param for studio ppg connections [merged]
    #28909 - feat(adapter-mariadb): Improve MariaDB adapter error reporting by surfacing underlying error causes [merged]

    👤 Suggested Assignees

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  3. Mimmox81 commented on Jan 1, 2026

    @Mimmox81
    Author

    Additional Details

    Complete Adapter Configuration

    import { PrismaMariaDb } from '@prisma/adapter-mariadb';
    
    const adapter = new PrismaMariaDb({
      host: config.host,
      port: config.port,
      user: config.user,
      password: config.password,
      database: config.database,
      connectionLimit: 10,
      connectTimeout: 10000,
      idleTimeout: 30,      // ← THIS IS IGNORED - connections stay forever
      minimumIdle: 2,
    });
    
    const prisma = new PrismaClient({ adapter });
    
    Evidence: Cleanup Logs
    
    Our cron runs every minute and kills connections idle for more than 10 seconds:
    
    2025-12-31 20:52:01 KILLED=3 idle connections (>10s)
    2025-12-31 20:53:01 KILLED=9 idle connections (>10s)
    2025-12-31 20:55:01 KILLED=3 idle connections (>10s)
    2025-12-31 20:58:01 KILLED=2 idle connections (>10s)
    2025-12-31 21:00:31 KILLED=20 idle connections (>10s)
    2025-12-31 21:03:01 KILLED=12 idle connections (>10s)
    2025-12-31 21:05:31 KILLED=6 idle connections (>10s)
    2025-12-31 21:07:31 KILLED=6 idle connections (>10s)
    
    Without this cleanup, connections accumulate until pool exhaustion.
    
    Workaround Script (Cron-based)
    
    #!/bin/bash
    # Runs every minute via cron
    IDLE_THRESHOLD=10
    
    KILLED=$(mysql -u $USER -h $HOST -p"$PASS" -N -e "
      SELECT COUNT(*) FROM information_schema.PROCESSLIST 
      WHERE COMMAND = 'Sleep' AND USER = '$DB_USER' AND TIME > ${IDLE_THRESHOLD};
    " 2>/dev/null)
    
    if [ "$KILLED" -gt 0 ]; then
      mysql -u $USER -h $HOST -p"$PASS" -N -e "
        SELECT CONCAT('KILL ', ID, ';') FROM information_schema.PROCESSLIST 
        WHERE COMMAND = 'Sleep' AND USER = '$DB_USER' AND TIME > ${IDLE_THRESHOLD};
      " | mysql -u $USER -h $HOST -p"$PASS"
      echo "$(date '+%Y-%m-%d %H:%M:%S') KILLED=$KILLED idle connections" >> /var/log/cleanup.log
    fi
    
    Expected vs Actual Behavior
    
    | Setting         | Expected                           | Actual                                       |
    |-----------------|------------------------------------|----------------------------------------------|
    | idleTimeout: 30 | Connection released after 30s idle | Connection stays in Sleep for 50-60+ seconds |
    | minimumIdle: 2  | Pool maintains ~2 warm connections | Pool grows unbounded                         |
    
    Environment
    
    - OS: Ubuntu 24.04 LTS
    - MariaDB: 10.11.15
    - Node.js: v20.x
    - PM2: Cluster mode (2 instances)
    - Prisma: 7.2.0
    - @prisma/adapter-mariadb: 7.2.0
    - mariadb driver: 3.4.0
    
    This workaround has been stable in production for weeks, but it's a band-aid. We'd appreciate a proper fix for idleTimeout propagation to the underlying mariadb driver.
  4. peterwake commented on Jan 21, 2026

    @peterwake

    @Mimmox81 I've had a similar issue but looking this and #29053 .. are you saying in 29053 that this issue is now (kind-of) fixed? Is it because you upgraded to a later version of something? Thanks.

  5. peterwake commented on Jan 21, 2026

    @peterwake

    Actually @Mimmox81 I did some more work on this this afternoon, and my issue was because I have 3 processes that were creating 10 connections each. So perhaps you have something like this where you have multiple threads of your app creating more connections than you'd expect.

  6. Mimmox81 commented on Feb 1, 2026

    @Mimmox81
    Author

    @peterwake you're right — we can confirm this is amplified by multi-process setups.

    Our setup:

    • Prisma 7.3.0 with @prisma/adapter-mariadb 7.3.0
    • MariaDB 10.11.15 on Ubuntu 24.04, Node.js v20
    • 2 PM2 cluster instances (each with connectionLimit: 10, minimumIdle: 2, idleTimeout: 10)
    • So 2 processes × 10 connections = 20 total pool connections

    What we observe (still, as of today Feb 1 2026):

    We run a cron cleanup script every 20 minutes that kills idle MySQL connections exceeding 35s. The data is very consistent:

    • ~30 connections killed every cycle, with idle_time of 46-47 seconds
    • A follow-up pass 30 seconds later catches 2-4 more at 58-59 seconds idle
    • Over the last 13 days: 24,860 connections killed across 2,198 cleanup cycles
    • Today alone (half day): 1,330 connections killed

    The configured idleTimeout: 10 is clearly being ignored by the adapter — connections sit in MySQL Sleep state for 46-59 seconds instead of being released after 10s. This happens consistently 24/7, not just under load.

    The workaround (cron killing idle connections from MySQL side) keeps the system stable, but it shouldn't be necessary. The underlying mariadb npm driver handles idleTimeout correctly when used directly — the issue is in how
    @prisma/adapter-mariadb propagates pool settings to the driver.

    Happy to provide additional diagnostics if helpful.

  7. added
    bug/2-confirmed
    on Feb 4, 2026
  8. added a commit that references this issue on Jul 22, 2026
    a39a763
  9. added a commit that references this issue on Aug 9, 2026
    6a177a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions