Skip to content

Bug: CacheManager setInterval missing .unref() prevents process exit #1256

@sparkling

Description

@sparkling

Summary

CacheManager.startCleanupTimer() in @claude-flow/memory calls setInterval(..., 60000) without .unref(), keeping the Node.js event loop alive indefinitely. Any CLI command that touches memory (memory store, memory search, etc.) cannot exit cleanly.

Root Cause

cache-manager.js line 310:

startCleanupTimer() {
    this.cleanupInterval = setInterval(() => {
        this.cleanupExpired();
    }, 60000);
    // MISSING: this.cleanupInterval.unref();
}

The CacheManager is instantiated via TieredCacheManagerthis.l1Cache = new CacheManager(...) whenever the bridge initializes. Since the constructor calls startCleanupTimer(), the 60-second housekeeping interval holds the event loop open.

Other timers in the same package (agentdb-backend.js:142, auto-memory-bridge.js:534) correctly call .unref(). sqljs-backend.js:81 has the same bug with its persistTimer.

Fix

Defect MM-002 in claude-flow-patch.

Add .unref() after each setInterval call in cache-manager.js and sqljs-backend.js. Housekeeping timers should not prevent process exit — they are best-effort cleanup, not critical work.

Op File Change
MM-002a cache-manager.js Add this.cleanupInterval.unref() after setInterval
MM-002b sqljs-backend.js Add this.persistTimer.unref() after setInterval

Files Affected

  • @claude-flow/memory/dist/cache-manager.js
  • @claude-flow/memory/dist/sqljs-backend.js

Affected Versions

ruflo (all versions)

Related Issues

  • None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions