Skip to content
TypeScript

fix(tailscale): a timed-out tailscale probe no longer outlives its call (#22900)

Theo Browne0d876e004aed
diff --git a/packages/tailscale/src/tailscale.test.ts b/packages/tailscale/src/tailscale.test.ts
index d128827b8e8..0b83cb3008d 100644
--- a/packages/tailscale/src/tailscale.test.ts
+++ b/packages/tailscale/src/tailscale.test.ts
@@ -1,4 +1,5 @@
import { assert, describe, it } from "@effect/vitest";
+import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Sink from "effect/Sink";
@@ -219,4 +220,29 @@ describe("tailscale", () => {
assertCarriesNoSecret(error, "tskey-auth-secret-token-value");
});
});
+
+ // regression: #21609 - without forceKillAfter a timed-out probe only gets
+ // SIGTERM, so a group member that ignores it outlives the call.
+ it.effect("escalates timed-out probes to SIGKILL", () => {
+ const killGraces: Array<number | undefined> = [];
+ const layer = layerSpawner(
+ ChildProcessSpawner.make((command) => {
+ if (command._tag === "StandardCommand") {
+ const { forceKillAfter } = command.options;
+ killGraces.push(
+ forceKillAfter === undefined
+ ? undefined
+ : Duration.toMillis(Duration.fromInputUnsafe(forceKillAfter)),
+ );
+ }
+ return Effect.succeed(mockHandle({ stdout: "{}" }));
+ }),
+ );
+
+ return Effect.gen(function* () {
+ yield* readTailscaleStatus.pipe(Effect.provide(layer));
+ yield* readTailscaleSshEnabled.pipe(Effect.provide(layer));
+ assert.deepEqual(killGraces, [500, 500]);
+ });
+ });
});
diff --git a/packages/tailscale/src/tailscale.ts b/packages/tailscale/src/tailscale.ts
index ece4aca1e31..1c803b27f1e 100644
--- a/packages/tailscale/src/tailscale.ts
+++ b/packages/tailscale/src/tailscale.ts
@@ -15,6 +15,13 @@ export const DEFAULT_TAILSCALE_SERVE_PORT = 443;
* that follows the timeout also takes time (`taskkill` on Windows).
*/
const TAILSCALE_STATUS_TIMEOUT = Duration.millis(3_500);
+/**
+ * How long a probe killed on timeout gets to exit after SIGTERM before its
+ * process group is SIGKILLed. Without it the spawner never escalates, so a group
+ * member that ignores SIGTERM outlives the call. Short because the timeout error
+ * only surfaces once cleanup finishes, and a healthy `tailscale` exits at once.
+ */
+const TAILSCALE_KILL_GRACE = Duration.millis(500);
const TAILSCALE_SERVE_TIMEOUT = Duration.seconds(10);
const TAILSCALE_PROBE_TIMEOUT = Duration.millis(2_500);
@@ -226,8 +233,11 @@ const readTailscaleOutput = Effect.fn("tailscale.readTailscaleOutput")(function*
subcommand,
argumentCount: args.length,
};
+ const command = ChildProcess.make(executable, [...args], {
+ forceKillAfter: TAILSCALE_KILL_GRACE,
+ });
return yield* Effect.gen(function* () {
- const child = yield* spawner.spawn(ChildProcess.make(executable, [...args])).pipe(
+ const child = yield* spawner.spawn(command).pipe(
Effect.mapError((cause) => new TailscaleCommandSpawnError({ ...commandContext, cause })),
// Spawning can also fail as a defect rather than a typed error - a
// non-directory entry on PATH makes node throw ENOTDIR synchronously.