Skip to content

fix(memory): add .unref() to housekeeping timers to prevent process hang#1269

Open
webdevpraveen wants to merge 1 commit intoruvnet:mainfrom
webdevpraveen:fix/timer-unref-process-exit
Open

fix(memory): add .unref() to housekeeping timers to prevent process hang#1269
webdevpraveen wants to merge 1 commit intoruvnet:mainfrom
webdevpraveen:fix/timer-unref-process-exit

Conversation

@webdevpraveen
Copy link

@webdevpraveen webdevpraveen commented Mar 2, 2026

Adds .unref() to two setInterval timers that prevent the Node.js process from exiting cleanly.

Problem

CacheManager.startCleanupTimer() and SqlJsBackend 's auto-persist timer both call setInterval() without .unref(), keeping the event loop alive indefinitely. This means any CLI command that touches memory (memory store, memory search, etc.) hangs after completing its work and never exits - users have to Ctrl+C to kill it.


Fix

Added .unref() after each setInterval call, guarded by an existence check for environments where .unref() may not be available:

  • v3/@claude-flow/memory/src/cache-manager.ts - cleanup timer (line ~397)
  • v3/@claude-flow/memory/src/sqljs-backend.ts - persist timer (line ~136)

Why this is safe

  • These are best-effort housekeeping timers, not critical work. The shutdown() methods already handle final cleanup/persist explicitly.
  • Other timers in the same package (agentdb-backend.js:142, auto-memory-bridge.js:534) already call .unref() correctly - this just brings the remaining two in line with that pattern.
  • Zero behavioral change when the process is still running; only affects exit behavior.

Fixes Issue #1256

CacheManager.startCleanupTimer() and SqlJsBackend auto-persist timer
call setInterval() without .unref(), keeping the Node.js event loop
alive indefinitely. Any CLI command that touches memory (memory store,
memory search, etc.) cannot exit cleanly.

Other timers in the same package (agentdb-backend.js:142,
auto-memory-bridge.js:534) correctly call .unref(). This commit
brings cache-manager.ts and sqljs-backend.ts in line with that pattern.

Fixes ruvnet#1256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant