Skip to content

Commit 0d876e0

Browse files
t3dotggfixfonclaude
authored
fix(tailscale): a timed-out tailscale probe no longer outlives its call (pingdotgg#22900)
Co-authored-by: fixfon <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 60dc0a0 commit 0d876e0

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎packages/tailscale/src/tailscale.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assert, describe, it } from "@effect/vitest";
2+
import * as Duration from "effect/Duration";
23
import * as Effect from "effect/Effect";
34
import * as Layer from "effect/Layer";
45
import * as Sink from "effect/Sink";
@@ -219,4 +220,29 @@ describe("tailscale", () => {
219220
assertCarriesNoSecret(error, "tskey-auth-secret-token-value");
220221
});
221222
});
223+
224+
// regression: #21609 - without forceKillAfter a timed-out probe only gets
225+
// SIGTERM, so a group member that ignores it outlives the call.
226+
it.effect("escalates timed-out probes to SIGKILL", () => {
227+
const killGraces: Array<number | undefined> = [];
228+
const layer = layerSpawner(
229+
ChildProcessSpawner.make((command) => {
230+
if (command._tag === "StandardCommand") {
231+
const { forceKillAfter } = command.options;
232+
killGraces.push(
233+
forceKillAfter === undefined
234+
? undefined
235+
: Duration.toMillis(Duration.fromInputUnsafe(forceKillAfter)),
236+
);
237+
}
238+
return Effect.succeed(mockHandle({ stdout: "{}" }));
239+
}),
240+
);
241+
242+
return Effect.gen(function* () {
243+
yield* readTailscaleStatus.pipe(Effect.provide(layer));
244+
yield* readTailscaleSshEnabled.pipe(Effect.provide(layer));
245+
assert.deepEqual(killGraces, [500, 500]);
246+
});
247+
});
222248
});

‎packages/tailscale/src/tailscale.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export const DEFAULT_TAILSCALE_SERVE_PORT = 443;
1515
* that follows the timeout also takes time (`taskkill` on Windows).
1616
*/
1717
const TAILSCALE_STATUS_TIMEOUT = Duration.millis(3_500);
18+
/**
19+
* How long a probe killed on timeout gets to exit after SIGTERM before its
20+
* process group is SIGKILLed. Without it the spawner never escalates, so a group
21+
* member that ignores SIGTERM outlives the call. Short because the timeout error
22+
* only surfaces once cleanup finishes, and a healthy `tailscale` exits at once.
23+
*/
24+
const TAILSCALE_KILL_GRACE = Duration.millis(500);
1825
const TAILSCALE_SERVE_TIMEOUT = Duration.seconds(10);
1926
const TAILSCALE_PROBE_TIMEOUT = Duration.millis(2_500);
2027

@@ -226,8 +233,11 @@ const readTailscaleOutput = Effect.fn("tailscale.readTailscaleOutput")(function*
226233
subcommand,
227234
argumentCount: args.length,
228235
};
236+
const command = ChildProcess.make(executable, [...args], {
237+
forceKillAfter: TAILSCALE_KILL_GRACE,
238+
});
229239
return yield* Effect.gen(function* () {
230-
const child = yield* spawner.spawn(ChildProcess.make(executable, [...args])).pipe(
240+
const child = yield* spawner.spawn(command).pipe(
231241
Effect.mapError((cause) => new TailscaleCommandSpawnError({ ...commandContext, cause })),
232242
// Spawning can also fail as a defect rather than a typed error - a
233243
// non-directory entry on PATH makes node throw ENOTDIR synchronously.

0 commit comments

Comments
 (0)