Merge pull request #4411 from rommapp/fix/db-pool-recycle

fix(db): recycle pooled connections before the server drops them
This commit is contained in:
Georges-Antoine Assi authored and GitHub committed 2026-09-10 11:01:32 -04:00
commit 6b86f7afd5
4 files changed
+20 -10

No files matched your search

+2
View File
@@ -72,6 +72,8 @@ DB_PASSWD: Final[str | None] = _get_env("DB_PASSWD")
DB_NAME: Final[str] = _get_env("DB_NAME", "romm")
DB_QUERY_JSON: Final[str | None] = _get_env("DB_QUERY_JSON")
ROMM_DB_DRIVER: Final[str] = _get_env("ROMM_DB_DRIVER", "mariadb")
# Kept under the idle `wait_timeout` a host may impose; -1 never recycles.
DB_POOL_RECYCLE_SECONDS: Final[int] = safe_int(_get_env("DB_POOL_RECYCLE_SECONDS"), 300)
# REDIS
REDIS_HOST: Final[str | None] = _get_env("REDIS_HOST")
+7 -2
View File
@@ -4,11 +4,16 @@ import time
from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker
from config import DEV_SQL_ECHO
from config import DB_POOL_RECYCLE_SECONDS, DEV_SQL_ECHO
from config.config_manager import ConfigManager
# A ping on a socket the server already closed blocks the worker until TCP gives
# up, so `pool_pre_ping` alone is not enough.
sync_engine = create_engine(
ConfigManager.get_db_engine(), pool_pre_ping=True, echo=False
ConfigManager.get_db_engine(),
pool_pre_ping=True,
pool_recycle=DB_POOL_RECYCLE_SECONDS,
echo=False,
)
sync_session = sessionmaker(bind=sync_engine, expire_on_commit=False)
+10 -8
View File
@@ -1545,14 +1545,16 @@ Falls back to `FakeRedis` in test mode.
#### Database
| Variable | Default | Description |
| ---------------- | --------- | ----------------------------------- |
| `ROMM_DB_DRIVER` | `mariadb` | `mariadb`, `mysql`, or `postgresql` |
| `DB_HOST` | | Database host |
| `DB_PORT` | `3306` | Database port |
| `DB_USER` | | Database user |
| `DB_PASSWD` | | Database password |
| `DB_NAME` | `romm` | Database name |
| Variable | Default | Description |
| ------------------------- | --------- | ------------------------------------------------------------------ |
| `ROMM_DB_DRIVER` | `mariadb` | `mariadb`, `mysql`, or `postgresql` |
| `DB_HOST` | | Database host |
| `DB_PORT` | `3306` | Database port |
| `DB_USER` | | Database user |
| `DB_PASSWD` | | Database password |
| `DB_NAME` | `romm` | Database name |
| `DB_QUERY_JSON` | | Extra connection parameters, as JSON |
| `DB_POOL_RECYCLE_SECONDS` | `300` | Retire a pooled connection after this long (`-1` to never recycle) |
#### Redis
+1
View File
@@ -14,6 +14,7 @@ DB_USER= # Database username (should match MARIADB_USER in MariaDB) [REQUIRED]
DB_PASSWD= # Database password (should match MARIADB_PASSWORD in MariaDB) [REQUIRED]
DB_ROOT_PASSWD= # Database root user password (only used by the bundled MariaDB container)
DB_QUERY_JSON= # Extra query parameters for the database connection, as JSON
DB_POOL_RECYCLE_SECONDS=300 # Retire a pooled connection after this long, before the server drops it for being idle (-1 to never recycle)
# Redis/Valkey
REDIS_HOST=127.0.0.1 # Host name of the Redis/Valkey instance