fix(cli): harden election edge cases

This commit is contained in:
Kit Langton 2026-07-07 22:11:14 -04:00
commit c61e93a1f3
2 changed files with 12 additions and 7 deletions

View file

@ -164,11 +164,12 @@ export namespace EffectFlock {
process.kill(owner.pid, 0)
return true
},
catch: (cause) => {
const code = cause && typeof cause === "object" && "code" in cause ? cause.code : undefined
return code !== "ESRCH"
},
}).pipe(Effect.orElseSucceed(() => false))
catch: (cause) => (cause && typeof cause === "object" && "code" in cause ? cause.code : undefined),
}).pipe(
// Only ESRCH proves the pid is gone; other errors (e.g. EPERM) mean a
// process exists, so never break a possibly live owner's lock.
Effect.catch((code) => Effect.succeed(code !== "ESRCH")),
)
if (!alive) return true
}