fix(clients): dropped connections say why in the client trace (#16200)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
24238fee32
commit
5cebd3b814
7 files changed
+235
-174
No files matched your search
@@ -802,7 +802,30 @@ export const make = Effect.fn("EnvironmentSupervisor.make")(function* (
|
||||
resetRetry: connectedExit.value,
|
||||
} satisfies AttemptOutcome;
|
||||
}
|
||||
return failureFromExit(target, connectedExit, true, connectedForMs >= BACKOFF_RESET_AFTER_MS);
|
||||
const outcome = failureFromExit(
|
||||
target,
|
||||
connectedExit,
|
||||
true,
|
||||
connectedForMs >= BACKOFF_RESET_AFTER_MS,
|
||||
);
|
||||
if (outcome._tag === "Failure") {
|
||||
// A live session ending is otherwise invisible in the client trace, so
|
||||
// record why, and how long it lasted, as its own root span.
|
||||
yield* Effect.void.pipe(
|
||||
Effect.withSpan("EnvironmentSupervisor.connectionLost", {
|
||||
root: true,
|
||||
attributes: {
|
||||
"environment.id": target.environmentId,
|
||||
"environment.label": target.label,
|
||||
"environment.target.kind": target._tag,
|
||||
"connection.connected_ms": connectedForMs,
|
||||
"connection.failure.reason": outcome.failure.error.reason,
|
||||
"connection.failure.detail": outcome.failure.error.detail,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
return outcome;
|
||||
}, Effect.ensuring(clearLease));
|
||||
|
||||
const waitForRetrySignal = Effect.fnUntraced(function* (delayMs: number) {
|
||||
|
||||
@@ -22,6 +22,7 @@ describe("isTransportConnectionErrorMessage", () => {
|
||||
|
||||
it("recognizes connection errors emitted by the Effect RPC session", () => {
|
||||
expect(isTransportConnectionErrorMessage("Test environment disconnected.")).toBe(true);
|
||||
expect(isTransportConnectionErrorMessage("Test environment stopped responding.")).toBe(true);
|
||||
expect(
|
||||
isTransportConnectionErrorMessage(
|
||||
"Test environment could not establish a WebSocket connection.",
|
||||
@@ -34,6 +35,7 @@ describe("isTransportConnectionErrorMessage", () => {
|
||||
it("recognizes relay connection errors that carry the network hint", () => {
|
||||
for (const sentence of [
|
||||
"Relay environment disconnected.",
|
||||
"Relay environment stopped responding.",
|
||||
"Relay environment could not establish a WebSocket connection.",
|
||||
]) {
|
||||
expect(isTransportConnectionErrorMessage(`${sentence} ${NETWORK_BLOCKING_HINT}`)).toBe(true);
|
||||
|
||||
@@ -10,7 +10,7 @@ const TRANSPORT_ERROR_PATTERNS = [
|
||||
// The RPC session appends the network hint for relay connections. Any other
|
||||
// trailing text means a different error that the user should still see.
|
||||
new RegExp(
|
||||
`\\b(?:is not connected|disconnected|could not establish a WebSocket connection)\\.(?: ${escapeRegExp(NETWORK_BLOCKING_HINT)})?$`,
|
||||
`\\b(?:is not connected|disconnected|stopped responding|could not establish a WebSocket connection)\\.(?: ${escapeRegExp(NETWORK_BLOCKING_HINT)})?$`,
|
||||
"i",
|
||||
),
|
||||
/\bClientProtocolError\b/i,
|
||||
|
||||
@@ -1108,7 +1108,10 @@ describe("RpcSessionFactory", () => {
|
||||
yield* TestClock.adjust("5 seconds");
|
||||
const error = yield* Fiber.join(closedFiber);
|
||||
expect(error).toBeInstanceOf(ConnectionTransientError);
|
||||
expect(error).toMatchObject({ reason: "transport" });
|
||||
expect(error).toMatchObject({
|
||||
reason: "transport",
|
||||
detail: "Test environment stopped responding.",
|
||||
});
|
||||
}).pipe(Effect.scoped, Effect.provide(TestClock.layer())),
|
||||
);
|
||||
|
||||
|
||||
@@ -170,18 +170,24 @@ export const make = Effect.fn("RpcSessionFactory.make")(function* (
|
||||
|
||||
const connected = yield* Deferred.make<void>();
|
||||
const disconnected = yield* Deferred.make<never, ConnectionTransientError>();
|
||||
// Set when the socket closes because pongs stopped, so the failure says so
|
||||
// instead of looking like the server closed the connection.
|
||||
const pingTimedOut = yield* Ref.make(false);
|
||||
const hooks = RpcClient.ConnectionHooks.of({
|
||||
onConnect: Deferred.succeed(connected, undefined).pipe(Effect.asVoid),
|
||||
onDisconnect: Deferred.isDone(connected).pipe(
|
||||
Effect.flatMap((wasConnected) =>
|
||||
onPingTimeout: Ref.set(pingTimedOut, true),
|
||||
onDisconnect: Effect.all([Deferred.isDone(connected), Ref.get(pingTimedOut)]).pipe(
|
||||
Effect.flatMap(([wasConnected, timedOut]) =>
|
||||
Deferred.fail(
|
||||
disconnected,
|
||||
new ConnectionTransientErrorClass({
|
||||
reason: "transport",
|
||||
detail: `${
|
||||
wasConnected
|
||||
? `${connection.label} disconnected.`
|
||||
: `${connection.label} could not establish a WebSocket connection.`
|
||||
!wasConnected
|
||||
? `${connection.label} could not establish a WebSocket connection.`
|
||||
: timedOut
|
||||
? `${connection.label} stopped responding.`
|
||||
: `${connection.label} disconnected.`
|
||||
}${networkHint}`,
|
||||
}),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user