Skip to content

Package services do not gracefully handle "Too many connections" errors. #1746

@junhaoliao

Description

@junhaoliao

Bug

Currently, the database connection logic in various components raises an exception immediately when the database server rejects a connection due to connection limits. This can cause cascading failures when the database is temporarily overloaded.

  1. Python Components (clp-package-utils, scripts):

    • Target: components/clp-py-utils/clp_py_utils/sql_adapter.py
    • Logic: Wrap _create_mariadb_connection and _create_mysql_connection with a retry loop catching mariadb.Error / mysql.connector.Error (specifically for "Too many connections").
  2. Core (C++):

    • Target: components/core/src/clp/MySQLDB.cpp
    • Logic: In the open or connection establishment method, check for MySQL error codes (e.g., CR_CONNECTION_ERROR, ER_CON_COUNT_ERROR) and retry with backoff.
  3. WebUI (Node.js/TypeScript):

    • Target: components/webui/server (uses @fastify/mysql).
    • Logic: Configure the connection pool to retry, or wrap the initial connection logic. @fastify/mysql might expose the underlying pool events or require a custom connection factory wrapper to handle retries during startup or pool acquisition.
  4. MCP Server (Python):

    • Target: components/clp-mcp-server (uses aiomysql).
    • Logic: Implement an async retry wrapper around the aiomysql.connect or pool creation calls.
  5. API Server (Rust):

    • Target: components/api-server (uses sqlx).
    • Logic: sqlx often has built-in connection pool features (max_connections, acquire_timeout), but explicit retries on "Too many connections" during initial pool creation or individual acquisition might need explicit handling (e.g., using ConnectOptions or a retry crate like backoff).

CLP version

21fa311

Environment

Ubuntu 22.04

Reproduction steps

MariaDB/MySQL ships with mysqlslap, which can spawn many connections concurrently.

Example: 200 connections

mysqlslap \
  --user=youruser \
  --password=yourpassword \
  --host=127.0.0.1 \
  --concurrency=200 \
  --iterations=1 \
  --create-schema=test \
  --query="SELECT 1;"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions