fix: read SESSION_LIFETIME from env var for session cleanup#282
Open
loris-av wants to merge 1 commit into
Open
fix: read SESSION_LIFETIME from env var for session cleanup#282loris-av wants to merge 1 commit into
loris-av wants to merge 1 commit into
Conversation
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).
This was referenced May 7, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The session cleanup timer in
McpServerPoolandMetaMcpServerPoolruns every 5 minutes but skips cleanup entirely whenconfigService.getSessionLifetime()returnsnull— 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_CONNECTIONSand refuses all new connections:All connectors then show 0 tools.
Fix
Add an env var fallback in
getSessionLifetime(): when the DB config table has noSESSION_LIFETIMEvalue,process.env.SESSION_LIFETIMEis read instead. The DB config (via Settings dashboard) still takes priority.This follows the same pattern as
MAX_TOTAL_CONNECTIONS(PR #280).Usage
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 ingetSessionLifetime()Related
MAX_TOTAL_CONNECTIONSenv var (same pattern)refresh_tokengrant (token refreshes create new sessions)