Skip to content

fix: use spawn+detach in tryStartDaemon to prevent daemon being killed on timeout#4

Merged
Lisztos merged 2 commits intomainfrom
fix/daemon-spawnSync-memory-leak
Mar 25, 2026
Merged

fix: use spawn+detach in tryStartDaemon to prevent daemon being killed on timeout#4
Lisztos merged 2 commits intomainfrom
fix/daemon-spawnSync-memory-leak

Conversation

@Lisztos
Copy link
Copy Markdown
Owner

@Lisztos Lisztos commented Mar 24, 2026

Ported from parcadei/Continuous-Claude-v3#153 by @marcuspuchalla


Problem

tryStartDaemon uses spawnSync with a 5s timeout that kills the child. The TLDR daemon takes 30-60s to index a large project, so it gets killed before finishing. With multiple sessions, this compounds into dozens of orphaned 3GB processes.

Fix

Replace spawnSync with spawn({ detached: true }) + child.unref() so the daemon runs as a true independent background process.

Impact

  • Daemon survives the initial indexing phase without being killed
  • No more orphaned daemon processes accumulating across sessions

marcuspuchalla and others added 2 commits February 22, 2026 16:28
…ng killed

spawnSync kills the child process when the timeout expires. The TLDR daemon
takes 30-60s to index a large project, so on timeout spawnSync sends SIGTERM,
killing the daemon. The next Claude session start finds no running daemon and
spawns another — repeat across sessions = dozens of orphaned 3GB processes.

Replace spawnSync with spawn({ detached: true }) + child.unref() so the daemon
runs as a true independent background process and survives after the hook exits.

The existing PID guard (isDaemonProcessRunning) already prevents duplicate
spawns when the PID file exists and the process is alive. This fix ensures the
daemon isn't killed immediately after being spawned, so the PID file stays valid.
- getPidPath now reads from .tldr/daemon.pid (matching the Python daemon)
  instead of /tmp/tldr-{hash}.pid which was never written by the daemon
- isDaemonProcessRunning now handles EPERM (process alive, different
  permissions) and cleans up stale PID files on ESRCH
- Rebuilt all dist bundles that import daemon-client

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Lisztos Lisztos merged commit afbb10b into main Mar 25, 2026
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.

2 participants