Skip to content

fix: read SESSION_LIFETIME from env var for session cleanup#282

Open
loris-av wants to merge 1 commit into
metatool-ai:mainfrom
loris-av:fix/session-lifetime-env-var
Open

fix: read SESSION_LIFETIME from env var for session cleanup#282
loris-av wants to merge 1 commit into
metatool-ai:mainfrom
loris-av:fix/session-lifetime-env-var

Conversation

@loris-av

Copy link
Copy Markdown

Problem

The session cleanup timer in McpServerPool and MetaMcpServerPool runs every 5 minutes but skips cleanup entirely when configService.getSessionLifetime() returns null — which is the default when no value is set in the DB config table via the Settings dashboard.

This means MCP sessions accumulate indefinitely, eventually saturating the connection pool. With 13 servers × 6 namespaces and OAuth token refreshes creating new sessions, the pool reaches MAX_TOTAL_CONNECTIONS and refuses all new connections:

Connection limit reached: 1000/1000. Refusing to create new connection.
Skipping connection for server metabase - connection limit reached

All connectors then show 0 tools.

Fix

Add an env var fallback in getSessionLifetime(): when the DB config table has no SESSION_LIFETIME value, process.env.SESSION_LIFETIME is read instead. The DB config (via Settings dashboard) still takes priority.

This follows the same pattern as MAX_TOTAL_CONNECTIONS (PR #280).

Usage

environment:
  - SESSION_LIFETIME=3600000  # 1 hour in ms — sessions older than this are cleaned up

Without this env var (and without DB config), behavior is unchanged: infinite sessions, cleanup skipped.

Changes

  • apps/backend/src/lib/config.service.ts: env var fallback in getSessionLifetime()

Related

The cleanup timer in McpServerPool and MetaMcpServerPool runs every 5
minutes but skips cleanup entirely when getSessionLifetime() returns
null (the default when no DB config is set). This means sessions
accumulate indefinitely, eventually saturating the connection pool.

This adds an env var fallback: when the DB config table has no
SESSION_LIFETIME value, process.env.SESSION_LIFETIME is read instead.
The DB config (via the Settings dashboard) still takes priority.

Example: SESSION_LIFETIME=3600000 (1 hour in ms) enables automatic
cleanup of sessions older than 1 hour.

This follows the same pattern as MAX_TOTAL_CONNECTIONS (PR metatool-ai#280).
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.

1 participant