Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

chore(daemon): small review notes from #131 and #139

Marcelito82ededa75df1
diff --git a/apps/desktop/src-tauri/src/daemon.rs b/apps/desktop/src-tauri/src/daemon.rs
index deeec02..a9143a5 100644
--- a/apps/desktop/src-tauri/src/daemon.rs
+++ b/apps/desktop/src-tauri/src/daemon.rs
@@ -1575,7 +1575,9 @@ done"#;
let dir = scratch_dir("stop-replacement");
let handler = Arc::new(Opened::default());
let probes = AtomicUsize::new(0);
- // Each start sees an unoccupied port, then a healthy newly spawned child.
+ // Each start sees an unoccupied port, then a healthy newly spawned child. This assumes
+ // exactly two health probes per start (admission's plan, then wait_ready): a start that
+ // probes more often breaks this test for a reason unrelated to the race.
let health = Arc::new(move || probes.fetch_add(1, Ordering::SeqCst) % 2 == 1);
let script = format!(r#"
trap 'echo stopping > "{0}/stopping"; i=0; while [ ! -f "{0}/release" ] && [ "$i" -lt 300 ]; do sleep 0.01; i=$((i+1)); done; exit 0' TERM
@@ -1616,6 +1618,8 @@ while :; do sleep 0.01; done
attempting.wait();
// With the buggy unlocked stop, force replacement installation before
// allowing stop to take its channel. With serialization, start must wait.
+ // The unfixed code takes this first branch (the child mutex is free while
+ // stop waits); the fixed code takes the second one below (stop holds it).
if !serialized {
completed.recv_timeout(Duration::from_secs(3)).unwrap().unwrap();
}
diff --git a/packages/daemon/src/cli.ts b/packages/daemon/src/cli.ts
index 4cfbecb..7d020e2 100644
--- a/packages/daemon/src/cli.ts
+++ b/packages/daemon/src/cli.ts
@@ -82,11 +82,12 @@ async function main(): Promise<void> {
process.stdout.write(`${startupMessage(daemon.url, config.dataDir, process.stdout.isTTY === true)}\n`);
if (windows) {
- const shutdown = () => {
+ const shutdown = (signal: string) => {
+ log(`received ${signal}, shutting down`);
void windows.close();
};
- process.on("SIGINT", shutdown);
- process.on("SIGTERM", shutdown);
+ process.on("SIGINT", () => shutdown("SIGINT"));
+ process.on("SIGTERM", () => shutdown("SIGTERM"));
// Only successful daemon.close AND native drain may report success. Never use
// daemon.closed directly here: it also settles when daemon.close rejects.
// On failure, retain the owner and set exitCode without abandoning native