Skip to content

fix(daemon): prevent self-PID detection from killing background daemon#1485

Open
sasa-tomic wants to merge 1 commit intoruvnet:mainfrom
sasa-tomic:fix/daemon-self-pid-detection
Open

fix(daemon): prevent self-PID detection from killing background daemon#1485
sasa-tomic wants to merge 1 commit intoruvnet:mainfrom
sasa-tomic:fix/daemon-self-pid-detection

Conversation

@sasa-tomic
Copy link
Copy Markdown

@sasa-tomic sasa-tomic commented Mar 30, 2026

Summary

  • Background daemon exits immediately after starting on every Linux/macOS install
  • checkExistingDaemon() reads daemon.pid (written by the forked child itself), finds the PID alive (it's checking itself via process.kill(pid, 0)), and returns early — skipping all worker scheduling
  • With no timers/refs in the event loop, Node.js exits cleanly (code 0)
  • Fix: skip self-PID in checkExistingDaemon() so the daemon doesn't mistake itself for another instance

Reproduction

ruflo daemon start        # Reports success
ruflo daemon status       # Shows STOPPED — process already exited

With strace -f, you can see the child process exits with exit_group(0) moments after starting.

Fix

One-line guard in checkExistingDaemon():

if (pid === process.pid) return null;

Test plan

  • ruflo daemon start → process stays alive
  • ruflo daemon status → shows Running
  • ruflo doctor → Daemon Status passes
  • Starting a second daemon still correctly detects the first and skips

In background mode, the forked child process writes its own PID to
daemon.pid before calling daemon.start(). checkExistingDaemon() then
reads this file, finds the PID is alive (it's checking itself), and
returns early thinking another daemon is already running. This skips
all worker scheduling, leaving no event-loop refs, so Node.js exits
immediately with code 0.

Add a self-PID check so the daemon doesn't mistake itself for another
running instance.
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