{"record":{"id":"93c7f342601ed189","repo":"ruvnet/ruflo","slug":"maximum-sessions-this-config-maxsessions-reac-93c7f3","errorCode":null,"errorMessage":"Maximum sessions (${this.config.maxSessions}) reached","messagePattern":"Maximum sessions \\((.+?)\\) reached","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/shared/src/mcp/session-manager.ts","lineNumber":81,"sourceCode":"  private totalClosed = 0;\n  private totalExpired = 0;\n\n  constructor(\n    private readonly logger: ILogger,\n    config: SessionConfig = {}\n  ) {\n    super();\n    this.config = { ...DEFAULT_SESSION_CONFIG, ...config };\n    this.startCleanupTimer();\n  }\n\n  /**\n   * Create a new session\n   */\n  createSession(transport: TransportType): MCPSession {\n    // Check max sessions\n    if (this.sessions.size >= this.config.maxSessions) {\n      throw new Error(`Maximum sessions (${this.config.maxSessions}) reached`);\n    }\n\n    const id = this.generateSessionId();\n    const now = new Date();\n\n    const session: MCPSession = {\n      id,\n      state: 'created',\n      transport,\n      createdAt: now,\n      lastActivityAt: now,\n      isInitialized: false,\n      isAuthenticated: false,\n    };\n\n    this.sessions.set(id, session);\n    this.totalCreated++;\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/shared/src/mcp/session-manager.ts#L63-L99","documentation":"MCPSessionManager caps concurrent sessions at config.maxSessions (merged over DEFAULT_SESSION_CONFIG in the constructor, which also starts a cleanup timer). createSession() throws when sessions.size has reached the cap, bounding per-process memory. Slots are only freed when sessions are removed on disconnect/close or reclaimed by the cleanup timer after timeout. The manager exposes getActiveSessions() and getSessionMetrics() for monitoring.","triggerScenarios":"More clients connecting via http/ws/stdio transports than maxSessions, without disconnecting; leaked sessions where a connection was created but initialize never completed and never closed; load tests spawning many short-lived clients; maxSessions configured below expected concurrency.","commonSituations":"Default cap too low for production traffic; clients crashing without closing so sessions linger until timeout; test suites sharing one manager with a small cap; forgetting to scale horizontally so a single process absorbs all connections.","solutions":["Raise maxSessions in the SessionManager config to match real concurrency (and confirm it in code, not just docs)","Free stuck slots: close stale sessions explicitly, or shorten the timeout config so the cleanup timer reclaims abandoned sessions faster","Fix client-side leaks so every connection disconnects cleanly (finally/close handlers)","If load is legitimate, run more server processes and load-balance instead of raising the cap unboundedly"],"exampleFix":"// before\nconst manager = new MCPSessionManager(); // default cap; throws under load\n\n// after\nconst manager = new MCPSessionManager({\n  maxSessions: 500,\n});\n// monitor before it saturates:\nsetInterval(() => console.log(manager.getActiveSessions().length), 30_000);","handlingStrategy":"validation","validationCode":"const MAX_SESSIONS = 500; // keep in sync with the manager config\nif (manager.getActiveSessions().length >= MAX_SESSIONS) {\n  return respond503(); // shed load at the edge instead of letting createSession throw\n}\nconst session = manager.createSession(transportType);","typeGuard":null,"tryCatchPattern":"try {\n  const session = manager.createSession(transportType);\n} catch (e) {\n  if (e instanceof Error && /Maximum sessions/.test(e.message)) {\n    return respond503WithRetryAfter(30); // capacity: back off, do not crash the handler\n  }\n  throw e;\n}","preventionTips":["Monitor getActiveSessions().length against the cap and alert before saturation","Always close sessions in finally blocks on the client side","Tune session timeout config so abandoned sessions free slots quickly","Return 503/backpressure at the edge rather than letting createSession throw mid-request"],"tags":["mcp","sessions","capacity","limits","configuration"],"backgroundTag":"session-limit-reached","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}