feat: add PID lockfile guard to prevent duplicate instances#565
Closed
Lafunamor wants to merge 1 commit into
Closed
feat: add PID lockfile guard to prevent duplicate instances#565Lafunamor wants to merge 1 commit into
Lafunamor wants to merge 1 commit into
Conversation
2d7495a to
fbfb866
Compare
e9020b7 to
d627aba
Compare
09e77d7 to
4e22fdc
Compare
Adds acquirePidLock() called at startup that writes the current PID to data/nanoclaw.pid and exits if another live process already holds the lock. Stale lock files (process no longer running) are cleaned up automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4e22fdc to
ccdd8cc
Compare
Collaborator
|
Closing as part of a stale issue/PR cleanup. If this is still relevant, please reopen and we'll take another look. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
acquirePidLock()called at the very start ofmain()that writes the current process PID todata/nanoclaw.pidprocess.on('exit')handler on clean shutdownMotivation
Running
npm run devtwice, or a service manager restarting before a previous instance fully exits, leads to two NanoClaw processes racing on the same SQLite database and IPC queues. The PID lock is a lightweight, dependency-free safeguard.Files changed
src/index.ts— addsDATA_DIRimport,acquirePidLock()function (~25 lines), and a single call inmain()Test plan
data/nanoclaw.pidis written with the correct PIDkill -9), then start again — verifies the stale lock file is cleaned up and startup succeedsSIGTERM) — verifies the PID file is removed on exit🤖 Generated with Claude Code