Skip to content

P1: Timer leaks - setTimeout/setInterval without cleanup #58

@aberemia24

Description

@aberemia24

🟡 HIGH SEVERITY - Resource Leak

Severity: P1

Locations:

  • src/mcp-proxy-server.ts:283, 316
  • src/mcp-client-pool.ts:521, 724
  • src/redis-cache-provider.ts:190

Impact:

  • Timers keep Node.js process alive
  • Memory accumulation
  • Graceful shutdown blocked

Examples:

// mcp-client-pool.ts:724
setTimeout(() => {
  process.kill(pid, 'SIGKILL');
}, 2000);
// ← No clearTimeout, timer ID not stored

// redis-cache-provider.ts:190
this.cleanupInterval = setInterval(() => {
  this.cleanup();
}, 60000);
// ← No clearInterval in disconnect/shutdown

Fix Pattern:

private timers: Set<NodeJS.Timeout> = new Set();

setTimeout(() => {...}, ms);
// Change to:
const timer = setTimeout(() => {...}, ms);
this.timers.add(timer);

async shutdown() {
  for (const timer of this.timers) {
    clearTimeout(timer);
  }
  this.timers.clear();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions