Skip to content

Commit 97c2cff

Browse files
only21milclaudecodexmaria-rcks
authored
fix(server): retain relay unregister events at normal log level (pingdotgg#21650)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 797bcb0 commit 97c2cff

2 files changed

Lines changed: 110 additions & 2 deletions

File tree

‎apps/server/src/cloud/ManagedEndpointRuntime.test.ts‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import * as Effect from "effect/Effect";
55
import * as Exit from "effect/Exit";
66
import * as Fiber from "effect/Fiber";
77
import * as Layer from "effect/Layer";
8+
import * as Logger from "effect/Logger";
89
import * as Option from "effect/Option";
910
import * as PlatformError from "effect/PlatformError";
1011
import * as Queue from "effect/Queue";
12+
import * as References from "effect/References";
1113
import * as Sink from "effect/Sink";
1214
import * as Stream from "effect/Stream";
1315
import * as TestClock from "effect/testing/TestClock";
@@ -148,6 +150,28 @@ describe("CloudManagedEndpointRuntime", () => {
148150
).toBe("warning");
149151
});
150152

153+
it("classifies connection unregistration apart from registration and routine output", () => {
154+
expect(
155+
ManagedEndpointRuntime.classifyRelayClientOutput(
156+
"2026-10-06T00:00:00Z INF Unregistered tunnel connection connIndex=0 event=0 ip=198.41.200.23",
157+
),
158+
).toBe("unregistered");
159+
for (const level of ["ERR", "WRN", "FTL", "PNC"]) {
160+
expect(
161+
ManagedEndpointRuntime.classifyRelayClientOutput(
162+
`2026-10-06T00:00:00Z ${level} Unregistered tunnel connection connIndex=0`,
163+
),
164+
).toBe("warning");
165+
}
166+
for (const line of [
167+
"2026-10-06T00:00:00Z INF Initiating graceful shutdown due to signal terminated ...",
168+
"2026-10-06T00:00:00Z INF Starting metrics server on 127.0.0.1:20241/metrics",
169+
"2026-10-06T00:00:00Z DBG Unregistered tunnel connection connIndex=0",
170+
]) {
171+
expect(ManagedEndpointRuntime.classifyRelayClientOutput(line)).toBe("debug");
172+
}
173+
});
174+
151175
it("recognizes tunnel authorization failures without matching ordinary transport errors", () => {
152176
expect(
153177
ManagedEndpointRuntime.isRejectedRelayClientTunnelOutput(
@@ -203,6 +227,83 @@ describe("CloudManagedEndpointRuntime", () => {
203227
}),
204228
);
205229

230+
it.effect("logs a connection unregistration at info with the connector token redacted", () => {
231+
const logs: Array<{ readonly level: string; readonly message: unknown }> = [];
232+
const unregistrationLogged = Deferred.makeUnsafe<void>();
233+
const logger = Logger.make(({ logLevel, message }) => {
234+
logs.push({ level: logLevel, message });
235+
if (Array.isArray(message) && message[0] === "Relay client tunnel connection unregistered") {
236+
Deferred.doneUnsafe(unregistrationLogged, Effect.void);
237+
}
238+
});
239+
240+
return Effect.gen(function* () {
241+
const config = {
242+
providerKind: "cloudflare_tunnel" as const,
243+
connectorToken: "secret-connector-token",
244+
tunnelId: "tunnel-1",
245+
};
246+
const encoder = new TextEncoder();
247+
const output = yield* Queue.unbounded<Uint8Array>();
248+
const spawner = ChildProcessSpawner.make(() =>
249+
Effect.gen(function* () {
250+
const handle = makeHandle({
251+
pid: 701,
252+
onKill: () => {},
253+
output: Stream.fromQueue(output),
254+
});
255+
yield* Effect.addFinalizer(() => handle.kill().pipe(Effect.ignore));
256+
return handle;
257+
}),
258+
);
259+
const runtime = yield* buildCloudManagedEndpointRuntime(spawner);
260+
yield* runtime.applyConfig(config);
261+
yield* Queue.offer(
262+
output,
263+
encoder.encode(
264+
"2026-10-06T00:00:00Z INF Unregistered tunnel connection connIndex=0 token=secret-connector-token\n",
265+
),
266+
);
267+
yield* Deferred.await(unregistrationLogged);
268+
269+
// An unregistration is not a registration, so the registration timeout still recovers.
270+
yield* TestClock.adjust(Duration.minutes(3));
271+
expect(Option.getOrNull(yield* Stream.runHead(runtime.recoveryRequests))).toEqual(config);
272+
273+
yield* Queue.offer(
274+
output,
275+
encoder.encode(
276+
"2026-10-06T00:00:01Z INF Starting metrics server on 127.0.0.1:20241/metrics\n" +
277+
"2026-10-06T00:00:01Z INF Registered tunnel connection connIndex=0\n",
278+
),
279+
);
280+
yield* Stream.runHead(runtime.tunnelConnected);
281+
282+
const relayLogs = logs.filter(
283+
({ message }) =>
284+
Array.isArray(message) && String(message[0]).startsWith("Relay client tunnel"),
285+
);
286+
expect(relayLogs.map(({ level, message }) => [level, (message as unknown[])[0]])).toEqual([
287+
["Info", "Relay client tunnel connection unregistered"],
288+
["Info", "Relay client tunnel connection registered"],
289+
]);
290+
expect((relayLogs[0]!.message as unknown[])[1]).toMatchObject({
291+
output:
292+
"2026-10-06T00:00:00Z INF Unregistered tunnel connection connIndex=0 token=<redacted>",
293+
});
294+
const logged = JSON.stringify(logs.map(({ message }) => message));
295+
expect(logged).not.toContain("secret-connector-token");
296+
expect(logged).not.toContain("Starting metrics server");
297+
}).pipe(
298+
Effect.provide(
299+
Layer.merge(
300+
Logger.layer([logger], { mergeWithExisting: false }),
301+
Layer.succeed(References.MinimumLogLevel, "Info"),
302+
),
303+
),
304+
);
305+
});
306+
206307
const tunnelConfig = {
207308
providerKind: "cloudflare_tunnel" as const,
208309
connectorToken: "token",

‎apps/server/src/cloud/ManagedEndpointRuntime.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,17 @@ function needsPinnedRelayClient(executable: RelayClient.RelayClientStatus): bool
124124
);
125125
}
126126

127-
export function classifyRelayClientOutput(line: string): "connected" | "warning" | "debug" {
127+
export function classifyRelayClientOutput(
128+
line: string,
129+
): "connected" | "unregistered" | "warning" | "debug" {
128130
if (/\bRegistered tunnel connection\b/iu.test(line)) {
129131
return "connected";
130132
}
131133
// cloudflared uses zerolog FTL/PNC for fatal/panic; classify them above debug too.
132-
return /\b(?:ERR|WRN|FTL|PNC)\b/u.test(line) ? "warning" : "debug";
134+
if (/\b(?:ERR|WRN|FTL|PNC)\b/u.test(line)) {
135+
return "warning";
136+
}
137+
return /\bINF\b.*\bUnregistered tunnel connection\b/u.test(line) ? "unregistered" : "debug";
133138
}
134139

135140
/** Edge rejection wording varies; any Unauthorized registration error counts. */
@@ -513,6 +518,8 @@ export const make = Effect.gen(function* () {
513518
),
514519
Effect.asVoid,
515520
);
521+
case "unregistered":
522+
return Effect.logInfo("Relay client tunnel connection unregistered", attributes);
516523
case "warning":
517524
if (/\btimeout: no recent network activity\b/u.test(line)) {
518525
return noteQuicStall(connector).pipe(

0 commit comments

Comments
 (0)