Skip to content

Bug: Scheduler leaks tasks when stale timeout is disabled #504

@MSNev

Description

@MSNev

Description

In the task scheduler implementation, when the stale timeout feature is disabled (set to 0 or negative), completed/rejected tasks are never cleaned up from the internal task queue. Over time this causes unbounded memory growth.

Impact

  • Memory leak in long-running applications
  • Gradual performance degradation as the task list grows
  • Eventually may cause OOM in Node.js services or browser tab crashes

Steps to Reproduce

javascript const scheduler = createTaskScheduler({ staleTimeout: 0 }); // Process many tasks over time for (let i = 0; i < 100000; i++) { scheduler.queue(() => Promise.resolve()); } // Internal task list never shrinks

Suggested Fix

Ensure tasks are removed from the internal list upon completion/rejection regardless of the stale timeout configuration. The stale timeout should only govern how long to wait for unresolved tasks, not whether completed tasks are cleaned up.

Severity

Medium — memory leak that manifests in long-running services.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions