Skip to content

everything: evict idle Streamable HTTP and SSE sessions #5558

Open

Description

@cliffhall

Problem

server-everything's Streamable HTTP transport keeps one NodeStreamableHTTPServerTransport (and one server instance) per session in a Map keyed by session id (src/everything/transports/streamableHttp.ts), and the deprecated HTTP+SSE transport does the same (src/everything/transports/sse.ts). A session is removed only when its client closes it, so sessions that are initialized and then abandoned stay in memory for the life of the process. Opening many sessions grows memory roughly linearly (about 0.2 MiB per session in a local test), with no bound.

This is not a security issue for this server: it is a test server for client developers, binds loopback by default, and documents that it has no authentication. It is still a resource leak that a long-running test instance can hit.

Expected behavior

Idle sessions are evicted after a period of inactivity, and their transport and server instance are closed and cleaned up (timers, subscriptions, simulated-update intervals).

Approach

  • Track the last activity per session and evict sessions idle longer than a timeout, configurable through an environment variable with a sensible default (and possibly a maximum session count).
  • Apply the same to the SSE transport, since it shares the pattern.
  • The 2026-07-28 path is stateless and is not affected.
  • Document the setting in src/everything/README.md.

Acceptance criteria

  • A test shows an idle session evicted after the timeout and its resources released, while an active session survives.
  • README documents the timeout.

Activity

  1. added this to the v2.6.0 milestone on Nov 18, 2026
  2. added
    enhancementNew feature or request
    server-everythingReference implementation for the Everything MCP server - src/everything
    on Nov 18, 2026
  3. Pierpaolo1223 commented on Nov 18, 2026

    @Pierpaolo1223

    Hi @cliffhall, thanks for opening this to track the fix!

    I actually reported this exact behavior via a security advisory, though I completely understand the rationale for treating it as a resource leak rather than a security issue given the server's purpose.

    For reference and to help verify the eventual fix, here are the numbers and the reproduction script I used during my analysis:

    • Memory growth: On a 128 MiB heap (--max-old-space-size=128), around 1,265 unclosed initialize requests are enough to trigger a V8 OOM abort (SIGABRT).
    • Affected path: Confirmed that the 2026-07-28 stateless path is unaffected, and the leak is isolated to the stateful session Map (and the equivalent SSE map).
    Reproduction script (Node.js)
    // Reproducer: the Everything Streamable HTTP transport keeps every 2025-era
    // session in an unbounded map. This script starts the built server with a small
    // heap, sends initialize POSTs, and shows that the process dies from heap
    // exhaustion instead of refusing or evicting sessions.
    //
    // Usage (from servers/):
    //   npm run build -w src/everything
    //   node repro_http_sessions.mjs
    //
    // Environment:
    //   REPRO_HEAP=128          heap cap in MiB for the child
    //   REPRO_LIMIT=3000        maximum initialize requests to send
    //   REPRO_CONCURRENCY=50    requests in flight
    //
    // Exit code 0 means the bug reproduced (the child died before the limit);
    // 1 means it did not reproduce at this limit.
    
    import { spawn } from "node:child_process";
    import { randomInt } from "node:crypto";
    import { fileURLToPath } from "node:url";
    import path from "node:path";
    
    const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)));
    const heapMiB = Number(process.env.REPRO_HEAP ?? 128);
    const limit = Number(process.env.REPRO_LIMIT ?? 3000);
    const concurrency = Number(process.env.REPRO_CONCURRENCY ?? 50);
    const port = 39000 + randomInt(0, 900);
    
    const child = spawn(
      process.execPath,
      [`--max-old-space-size=${heapMiB}`, "src/everything/dist/index.js", "streamableHttp"],
      {
        cwd: root,
        env: { ...process.env, PORT: String(port) },
        stdio: ["ignore", "pipe", "pipe"],
      },
    );
    
    let log = "";
    const keep = (chunk) => {
      log += chunk.toString();
      if (log.length > 64 * 1024) log = log.slice(-32 * 1024);
    };
    child.stdout.on("data", keep);
    child.stderr.on("data", keep);
    
    const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
    
    async function waitForListening(timeoutMs = 10_000) {
      const started = Date.now();
      while (Date.now() - started < timeoutMs) {
        if (log.includes("listening")) return true;
        if (child.exitCode !== null) return false;
        await sleep(50);
      }
      return false;
    }
    
    async function initialize(i) {
      const response = await fetch(`http://127.0.0.1:${port}/mcp`, {
        method: "POST",
        headers: {
          "content-type": "application/json",
          accept: "application/json, text/event-stream",
        },
        body: JSON.stringify({
          jsonrpc: "2.0",
          id: i,
          method: "initialize",
          params: {
            protocolVersion: "2025-11-25",
            capabilities: {},
            clientInfo: { name: `repro-${i}`, version: "1" },
          },
        }),
        signal: AbortSignal.timeout(5_000),
      });
      const session = response.headers.get("mcp-session-id");
      await response.body?.cancel();
      return session;
    }
    
    if (!(await waitForListening())) {
      console.error("server did not start:\n" + log);
      child.kill("SIGKILL");
      process.exit(2);
    }
    
    console.log(
      `server on ${port}, heap ${heapMiB} MiB, limit ${limit} sessions, concurrency ${concurrency}`,
    );
    
    let ok = 0;
    let failed = 0;
    const sessions = new Set();
    
    for (let i = 1; i <= limit; i += concurrency) {
      if (child.exitCode !== null || child.signalCode !== null) break;
      const batch = [];
      for (let k = 0; k < concurrency && i + k <= limit; k++) {
        const id = i + k;
        batch.push(
          initialize(id)
            .then((session) => {
              if (session) sessions.add(session);
              ok++;
            })
            .catch(() => {
              failed++;
            }),
        );
      }
      await Promise.all(batch);
      if (i % 250 === 0) {
        console.log(`sent ${i}: ok ${ok}, failed ${failed}, sessions ${sessions.size}`);
      }
    }
    
    // Give the OOM a moment to surface if it is in progress.
    await sleep(1_500);
    
    const dead = child.exitCode !== null || child.signalCode !== null;
    console.log(
      `result: ok ${ok}, failed ${failed}, unique sessions ${sessions.size}, alive ${!dead}`,
    );
    if (dead) {
      console.log(`child exit code ${child.exitCode}, signal ${child.signalCode}`);
      console.log("last server output:\n" + log.split("\n").slice(-12).join("\n"));
    } else {
      child.kill("SIGKILL");
    }
    
    process.exit(dead ? 0 : 1);

    When the fix is merged for v2.6.0, I'd really appreciate a quick shout-out or Reported-by credit in the commit/release notes. Thanks!

  4. self-assigned this
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestserver-everythingReference implementation for the Everything MCP server - src/everythingv2

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions