feat: make maxTotalConnections configurable via env var#280
Open
loris-av wants to merge 1 commit into
Open
Conversation
loris-av
added a commit
to loris-av/metamcp
that referenced
this pull request
Apr 14, 2026
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 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
McpServerPoolconstructor hardcodesmaxTotalConnections = 100. For deployments with many MCP servers and namespaces, the connection pool saturates at 100 connections, causing new connections to be silently refused with a warning log:There is no way to raise this limit without modifying the source code.
Solution
Read the limit from the
MAX_TOTAL_CONNECTIONSenvironment variable at startup, falling back to100if unset:This is a one-line change with zero impact on existing deployments (default stays at 100).
Testing
MAX_TOTAL_CONNECTIONSset: pool behaves exactly as before (limit = 100).MAX_TOTAL_CONNECTIONS=500: pool allows up to 500 total connections.