Skip to content

Commit 9c19aa9

Browse files
fix(tailscale): serve setup no longer times out on a long success summary (pingdotgg#34743)
1 parent 8ea4a88 commit 9c19aa9

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { assert, describe, it } from "@effect/vitest";
2+
import * as Deferred from "effect/Deferred";
23
import * as Duration from "effect/Duration";
34
import * as Effect from "effect/Effect";
5+
import * as Exit from "effect/Exit";
6+
import * as Fiber from "effect/Fiber";
47
import * as Layer from "effect/Layer";
58
import * as Sink from "effect/Sink";
69
import * as Stream from "effect/Stream";
10+
import * as TestClock from "effect/testing/TestClock";
711
import { ChildProcessSpawner } from "effect/process";
812
import * as HostProcess from "@t3tools/shared/HostProcess";
913

@@ -317,6 +321,45 @@ describe("tailscale", () => {
317321
});
318322
});
319323

324+
// regression: #34736 - a full stdout pipe blocks the child before it exits.
325+
it.effect("drains serve stdout so a long success summary does not time out", () =>
326+
Effect.gen(function* () {
327+
const stdoutDrained = yield* Deferred.make<void>();
328+
const layer = layerSpawner(
329+
ChildProcessSpawner.make(() =>
330+
Effect.succeed(
331+
ChildProcessSpawner.makeHandle({
332+
pid: ChildProcessSpawner.ProcessId(1),
333+
exitCode: Deferred.await(stdoutDrained).pipe(
334+
Effect.as(ChildProcessSpawner.ExitCode(0)),
335+
),
336+
isRunning: Effect.succeed(true),
337+
kill: () => Effect.void,
338+
unref: Effect.succeed(Effect.void),
339+
stdin: Sink.drain,
340+
stdout: Stream.make(encoder.encode("https://example.ts.net/\n")).pipe(
341+
Stream.ensuring(Deferred.succeed(stdoutDrained, undefined)),
342+
),
343+
stderr: Stream.empty,
344+
all: Stream.empty,
345+
getInputFd: () => Sink.drain,
346+
getOutputFd: () => Stream.empty,
347+
}),
348+
),
349+
),
350+
);
351+
352+
const fiber = yield* ensureTailscaleServe({ localPort: 3773 }).pipe(
353+
Effect.provide(layer),
354+
Effect.exit,
355+
Effect.forkChild,
356+
);
357+
yield* TestClock.adjust("11 seconds");
358+
const exit = yield* Fiber.join(fiber);
359+
assert.isTrue(Exit.isSuccess(exit), String(exit));
360+
}),
361+
);
362+
320363
// regression: #21609 - without forceKillAfter a timed-out probe only gets
321364
// SIGTERM, so a group member that ignores it outlives the call.
322365
it.effect("escalates timed-out probes to SIGKILL", () => {

‎packages/tailscale/src/tailscale.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,13 @@ const runTailscaleCommand = Effect.fn("tailscale.runTailscaleCommand")(function*
405405
Effect.fail(new TailscaleCommandSpawnError({ ...commandContext, cause })),
406406
),
407407
);
408-
const [stderr, exitCode] = yield* Effect.all(
409-
[collectStderr(child.stderr), child.exitCode.pipe(Effect.map(Number))],
408+
// An unread stdout pipe fills on a long success summary and blocks the child before it exits.
409+
const [, stderr, exitCode] = yield* Effect.all(
410+
[
411+
Stream.runDrain(child.stdout),
412+
collectStderr(child.stderr),
413+
child.exitCode.pipe(Effect.map(Number)),
414+
],
410415
{ concurrency: "unbounded" },
411416
).pipe(
412417
Effect.mapError((cause) => new TailscaleCommandOutputError({ ...commandContext, cause })),

0 commit comments

Comments
 (0)