Skip to content

Commit 041d643

Browse files
committed
fix(server): bound the environment label probe at startup
Server startup waits for the environment label. On Linux without a PRETTY_HOSTNAME in /etc/machine-info, the label comes from `hostnamectl --pretty`, which ran with the process runner's 60 s default. Where systemd-hostnamed cannot start, such as unprivileged LXC containers, every start could stall for up to a minute before falling back to the hostname. Give the probe the same 5 s limit as the sibling machine probe. The existing non-zero-exit check already treats a timed-out run as no label.
1 parent 3da48c1 commit 041d643

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { assert, it } from "@effect/vitest";
2+
import * as HostProcess from "@t3tools/shared/HostProcess";
3+
import * as Effect from "effect/Effect";
4+
import * as Fiber from "effect/Fiber";
5+
import * as FileSystem from "effect/FileSystem";
6+
import * as Layer from "effect/Layer";
7+
import * as Sink from "effect/Sink";
8+
import * as Stream from "effect/Stream";
9+
import * as TestClock from "effect/testing/TestClock";
10+
import { ChildProcessSpawner } from "effect/process";
11+
12+
import * as ProcessRunner from "../processRunner.ts";
13+
import { resolveServerEnvironmentLabel } from "./ServerEnvironmentLabel.ts";
14+
15+
const neverExits = ChildProcessSpawner.make(() =>
16+
Effect.succeed(
17+
ChildProcessSpawner.makeHandle({
18+
pid: ChildProcessSpawner.ProcessId(1),
19+
exitCode: Effect.never,
20+
isRunning: Effect.succeed(true),
21+
kill: () => Effect.void,
22+
unref: Effect.succeed(Effect.void),
23+
stdin: Sink.drain,
24+
stdout: Stream.never,
25+
stderr: Stream.never,
26+
all: Stream.empty,
27+
getInputFd: () => Sink.drain,
28+
getOutputFd: () => Stream.empty,
29+
}),
30+
),
31+
);
32+
33+
it.effect("falls back to the hostname when hostnamectl never answers", () =>
34+
Effect.gen(function* () {
35+
// Without /etc/machine-info the label comes from hostnamectl, which waits on D-Bus.
36+
const label = yield* resolveServerEnvironmentLabel({ cwdBaseName: "project" }).pipe(
37+
Effect.provideService(HostProcess.Platform, "linux"),
38+
Effect.provideService(HostProcess.Hostname, "devbox"),
39+
Effect.provide(
40+
Layer.mergeAll(
41+
FileSystem.layerNoop({ exists: () => Effect.succeed(false) }),
42+
ProcessRunner.layer.pipe(
43+
Layer.provide(Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, neverExits)),
44+
),
45+
),
46+
),
47+
Effect.forkChild,
48+
);
49+
yield* TestClock.adjust("5 seconds");
50+
assert.equal(yield* Fiber.join(label), "devbox");
51+
}),
52+
);

‎apps/server/src/environment/ServerEnvironmentLabel.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ const runFriendlyLabelCommand = Effect.fn("runFriendlyLabelCommand")(function* (
116116
.run({
117117
command: input.command,
118118
args: input.args,
119+
// Server startup waits on this; hostnamectl can block on D-Bus when hostnamed is down.
120+
timeout: "5 seconds",
119121
timeoutBehavior: "timedOutResult",
120122
})
121123
.pipe(

0 commit comments

Comments
 (0)