Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3fa2a2553 | ||
|
|
9143d3bbe0 |
No files matched your search
@@ -17,7 +17,7 @@ import {
|
||||
SshLaunchError,
|
||||
SshPairingError,
|
||||
SshPasswordPromptError,
|
||||
type SshReadinessError,
|
||||
SshReadinessError,
|
||||
} from "@t3tools/ssh/errors";
|
||||
import { SshEnvironmentManager, type RemoteT3RunnerOptions } from "@t3tools/ssh/tunnel";
|
||||
import * as Context from "effect/Context";
|
||||
@@ -25,7 +25,6 @@ import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient } from "effect/unstable/http";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
@@ -80,13 +79,11 @@ function discoverDesktopSshHostsEffect(input?: { readonly homeDir?: string }) {
|
||||
return discoverSshHosts(input ?? {});
|
||||
}
|
||||
|
||||
const isSshPasswordPromptError = Schema.is(SshPasswordPromptError);
|
||||
|
||||
export function isDesktopSshPasswordPromptCancellation(
|
||||
error: unknown,
|
||||
): error is SshPasswordPromptError {
|
||||
return (
|
||||
isSshPasswordPromptError(error) &&
|
||||
error instanceof SshPasswordPromptError &&
|
||||
DesktopSshPasswordPrompts.isDesktopSshPasswordPromptCancellation(error.cause)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { assert, describe, it } from "@effect/vitest";
|
||||
import { SshHttpBridgeError } from "@t3tools/ssh/errors";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
|
||||
|
||||
import * as DesktopSshRemoteApi from "./DesktopSshRemoteApi.ts";
|
||||
@@ -32,8 +31,6 @@ function makeLayer(
|
||||
);
|
||||
}
|
||||
|
||||
const isSshHttpBridgeError = Schema.is(SshHttpBridgeError);
|
||||
|
||||
describe("DesktopSshRemoteApi", () => {
|
||||
it.effect("fetches and decodes the remote environment descriptor", () => {
|
||||
const requestUrls: string[] = [];
|
||||
@@ -76,7 +73,7 @@ describe("DesktopSshRemoteApi", () => {
|
||||
|
||||
assert.instanceOf(error, DesktopSshRemoteApi.DesktopSshRemoteApiError);
|
||||
assert.equal(error.operation, "fetch-environment-descriptor");
|
||||
assert.equal(isSshHttpBridgeError(error.cause), false);
|
||||
assert.equal(error.cause instanceof SshHttpBridgeError, false);
|
||||
}).pipe(Effect.provide(layer));
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { DesktopSshPasswordPromptRequest } from "@t3tools/contracts";
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
import { useCallback, useEffect, useId, useRef, useState, type RefObject } from "react";
|
||||
|
||||
import { Button } from "../ui/button";
|
||||
import {
|
||||
@@ -28,16 +28,10 @@ function getPromptErrorMessage(error: unknown): string {
|
||||
: message;
|
||||
}
|
||||
|
||||
export function SshPasswordPromptDialog() {
|
||||
const EXPIRED_PROMPT_ERROR = "This SSH password prompt expired. Try connecting again.";
|
||||
|
||||
function useSshPasswordPromptQueue() {
|
||||
const [queue, setQueue] = useState<readonly DesktopSshPasswordPromptRequest[]>([]);
|
||||
const [password, setPassword] = useState("");
|
||||
const [isResponding, setIsResponding] = useState(false);
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
const [responseError, setResponseError] = useState<string | null>(null);
|
||||
const currentRequest = queue[0] ?? null;
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const isRespondingRef = useRef(false);
|
||||
const formId = useId();
|
||||
|
||||
useEffect(() => {
|
||||
const bridge = window.desktopBridge;
|
||||
@@ -50,14 +44,23 @@ export function SshPasswordPromptDialog() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setPassword("");
|
||||
setResponseError(null);
|
||||
if (!currentRequest) {
|
||||
return;
|
||||
}
|
||||
const removeCurrentPrompt = useCallback((requestId: string) => {
|
||||
setQueue((currentQueue) =>
|
||||
currentQueue[0]?.requestId === requestId ? currentQueue.slice(1) : currentQueue,
|
||||
);
|
||||
}, []);
|
||||
|
||||
setNow(Date.now());
|
||||
return {
|
||||
currentRequest: queue[0] ?? null,
|
||||
removeCurrentPrompt,
|
||||
};
|
||||
}
|
||||
|
||||
function useSshPasswordPromptFocus(
|
||||
requestId: string,
|
||||
inputRef: RefObject<HTMLInputElement | null>,
|
||||
) {
|
||||
useEffect(() => {
|
||||
const frame = window.requestAnimationFrame(() => {
|
||||
inputRef.current?.focus();
|
||||
inputRef.current?.select();
|
||||
@@ -65,50 +68,72 @@ export function SshPasswordPromptDialog() {
|
||||
return () => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, [currentRequest]);
|
||||
}, [inputRef, requestId]);
|
||||
}
|
||||
|
||||
function useSshPasswordPromptNow(requestId: string) {
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
const interval = window.setInterval(() => {
|
||||
setNow(Date.now());
|
||||
}, 1_000);
|
||||
return () => {
|
||||
window.clearInterval(interval);
|
||||
};
|
||||
}, [currentRequest]);
|
||||
}, [requestId]);
|
||||
|
||||
const expiresAtMs = currentRequest ? Date.parse(currentRequest.expiresAt) : Number.NaN;
|
||||
return now;
|
||||
}
|
||||
|
||||
export function SshPasswordPromptDialog() {
|
||||
const { currentRequest, removeCurrentPrompt } = useSshPasswordPromptQueue();
|
||||
|
||||
if (!currentRequest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<SshPasswordPromptRequestDialog
|
||||
key={currentRequest.requestId}
|
||||
currentRequest={currentRequest}
|
||||
removeCurrentPrompt={removeCurrentPrompt}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SshPasswordPromptRequestDialog({
|
||||
currentRequest,
|
||||
removeCurrentPrompt,
|
||||
}: {
|
||||
currentRequest: DesktopSshPasswordPromptRequest;
|
||||
removeCurrentPrompt: (requestId: string) => void;
|
||||
}) {
|
||||
const [password, setPassword] = useState("");
|
||||
const [isResponding, setIsResponding] = useState(false);
|
||||
const [responseError, setResponseError] = useState<string | null>(null);
|
||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||
const isRespondingRef = useRef(false);
|
||||
const formId = useId();
|
||||
const now = useSshPasswordPromptNow(currentRequest.requestId);
|
||||
useSshPasswordPromptFocus(currentRequest.requestId, inputRef);
|
||||
|
||||
const expiresAtMs = Date.parse(currentRequest.expiresAt);
|
||||
const remainingMs = Number.isFinite(expiresAtMs) ? Math.max(0, expiresAtMs - now) : null;
|
||||
const isExpired = remainingMs !== null && remainingMs <= 0;
|
||||
const remainingSeconds = remainingMs === null ? null : Math.ceil(remainingMs / 1_000);
|
||||
const remainingLabel =
|
||||
remainingSeconds === null ? null : formatRemainingSeconds(remainingSeconds);
|
||||
|
||||
useEffect(() => {
|
||||
if (isExpired) {
|
||||
setResponseError("This SSH password prompt expired. Try connecting again.");
|
||||
}
|
||||
}, [isExpired]);
|
||||
|
||||
const removeCurrentPrompt = (requestId: string) => {
|
||||
setQueue((currentQueue) =>
|
||||
currentQueue[0]?.requestId === requestId ? currentQueue.slice(1) : currentQueue,
|
||||
);
|
||||
setPassword("");
|
||||
setResponseError(null);
|
||||
};
|
||||
const displayedError = isExpired ? EXPIRED_PROMPT_ERROR : responseError;
|
||||
|
||||
const respond = async (nextPassword: string | null) => {
|
||||
if (!currentRequest || isRespondingRef.current) {
|
||||
if (isRespondingRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const requestId = currentRequest.requestId;
|
||||
if (nextPassword !== null && isExpired) {
|
||||
setResponseError("This SSH password prompt expired. Try connecting again.");
|
||||
setResponseError(EXPIRED_PROMPT_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -198,8 +223,8 @@ export function SshPasswordPromptDialog() {
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{responseError ? (
|
||||
<p className="text-sm text-destructive">{responseError}</p>
|
||||
{displayedError ? (
|
||||
<p className="text-sm text-destructive">{displayedError}</p>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Use SSH keys to avoid repeated password prompts on new SSH sessions.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+38
-95
@@ -1,103 +1,46 @@
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Data from "effect/Data";
|
||||
|
||||
export class SshHostDiscoveryError extends Schema.TaggedErrorClass<SshHostDiscoveryError>()(
|
||||
"SshHostDiscoveryError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.Defect,
|
||||
},
|
||||
) {}
|
||||
export class SshHostDiscoveryError extends Data.TaggedError("SshHostDiscoveryError")<{
|
||||
readonly message: string;
|
||||
readonly cause: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshInvalidTargetError extends Schema.TaggedErrorClass<SshInvalidTargetError>()(
|
||||
"SshInvalidTargetError",
|
||||
{
|
||||
message: Schema.String,
|
||||
},
|
||||
) {}
|
||||
export class SshInvalidTargetError extends Data.TaggedError("SshInvalidTargetError")<{
|
||||
readonly message: string;
|
||||
}> {}
|
||||
|
||||
export class SshCommandError extends Schema.TaggedErrorClass<SshCommandError>()("SshCommandError", {
|
||||
message: Schema.String,
|
||||
command: Schema.Array(Schema.String),
|
||||
exitCode: Schema.NullOr(Schema.Number),
|
||||
stderr: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshCommandError extends Data.TaggedError("SshCommandError")<{
|
||||
readonly message: string;
|
||||
readonly command: readonly string[];
|
||||
readonly exitCode: number | null;
|
||||
readonly stderr: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshLaunchError extends Schema.TaggedErrorClass<SshLaunchError>()("SshLaunchError", {
|
||||
message: Schema.String,
|
||||
stdout: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshLaunchError extends Data.TaggedError("SshLaunchError")<{
|
||||
readonly message: string;
|
||||
readonly stdout: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshPairingError extends Schema.TaggedErrorClass<SshPairingError>()("SshPairingError", {
|
||||
message: Schema.String,
|
||||
stdout: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
}) {}
|
||||
export class SshPairingError extends Data.TaggedError("SshPairingError")<{
|
||||
readonly message: string;
|
||||
readonly stdout: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshHttpBridgeError extends Schema.TaggedErrorClass<SshHttpBridgeError>()(
|
||||
"SshHttpBridgeError",
|
||||
{
|
||||
message: Schema.String,
|
||||
status: Schema.optional(Schema.Number),
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshHttpBridgeError extends Data.TaggedError("SshHttpBridgeError")<{
|
||||
readonly message: string;
|
||||
readonly status?: number;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshReadinessProbeFailedError extends Schema.TaggedErrorClass<SshReadinessProbeFailedError>()(
|
||||
"SshReadinessProbeFailedError",
|
||||
{
|
||||
message: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshReadinessError extends Data.TaggedError("SshReadinessError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
|
||||
export class SshReadinessProbeTimedOutError extends Schema.TaggedErrorClass<SshReadinessProbeTimedOutError>()(
|
||||
"SshReadinessProbeTimedOutError",
|
||||
{
|
||||
message: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
attempt: Schema.Number,
|
||||
probeTimeoutMs: Schema.Number,
|
||||
},
|
||||
) {}
|
||||
|
||||
export class SshReadinessTimedOutError extends Schema.TaggedErrorClass<SshReadinessTimedOutError>()(
|
||||
"SshReadinessTimedOutError",
|
||||
{
|
||||
message: Schema.String,
|
||||
baseUrl: Schema.String,
|
||||
requestUrl: Schema.String,
|
||||
timeoutMs: Schema.Number,
|
||||
intervalMs: Schema.Number,
|
||||
probeTimeoutMs: Schema.Number,
|
||||
attempts: Schema.Number,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
|
||||
export type SshReadinessError =
|
||||
| SshReadinessProbeFailedError
|
||||
| SshReadinessProbeTimedOutError
|
||||
| SshReadinessTimedOutError;
|
||||
|
||||
const isSshReadinessProbeFailedError = Schema.is(SshReadinessProbeFailedError);
|
||||
const isSshReadinessProbeTimedOutError = Schema.is(SshReadinessProbeTimedOutError);
|
||||
const isSshReadinessTimedOutError = Schema.is(SshReadinessTimedOutError);
|
||||
|
||||
export function isSshReadinessError(cause: unknown): cause is SshReadinessError {
|
||||
return (
|
||||
isSshReadinessProbeFailedError(cause) ||
|
||||
isSshReadinessProbeTimedOutError(cause) ||
|
||||
isSshReadinessTimedOutError(cause)
|
||||
);
|
||||
}
|
||||
|
||||
export class SshPasswordPromptError extends Schema.TaggedErrorClass<SshPasswordPromptError>()(
|
||||
"SshPasswordPromptError",
|
||||
{
|
||||
message: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
export class SshPasswordPromptError extends Data.TaggedError("SshPasswordPromptError")<{
|
||||
readonly message: string;
|
||||
readonly cause?: unknown;
|
||||
}> {}
|
||||
@@ -242,9 +242,9 @@ describe("ssh tunnel scripts", () => {
|
||||
Effect.result(
|
||||
waitForHttpReady({
|
||||
baseUrl: "http://127.0.0.1:41773/",
|
||||
timeout: Duration.seconds(1),
|
||||
interval: Duration.millis(100),
|
||||
probeTimeout: Duration.millis(250),
|
||||
timeoutMs: 1_000,
|
||||
intervalMs: 100,
|
||||
probeTimeoutMs: 250,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
+46
-86
@@ -45,20 +45,16 @@ import {
|
||||
SshLaunchError,
|
||||
SshPairingError,
|
||||
SshPasswordPromptError,
|
||||
SshReadinessProbeFailedError,
|
||||
SshReadinessProbeTimedOutError,
|
||||
SshReadinessTimedOutError,
|
||||
isSshReadinessError,
|
||||
type SshReadinessError,
|
||||
SshReadinessError,
|
||||
} from "./errors.ts";
|
||||
|
||||
export const DEFAULT_REMOTE_PORT = 3773;
|
||||
const REMOTE_PORT_SCAN_WINDOW = 200;
|
||||
const SSH_READY_TIMEOUT = Duration.seconds(20);
|
||||
const SSH_READY_PROBE_TIMEOUT = Duration.seconds(1);
|
||||
const TUNNEL_SHUTDOWN_TIMEOUT = Duration.seconds(2);
|
||||
const REMOTE_READY_TIMEOUT = Duration.seconds(15);
|
||||
const REMOTE_REUSE_READY_TIMEOUT = Duration.seconds(2);
|
||||
const SSH_READY_TIMEOUT_MS = 20_000;
|
||||
const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
|
||||
const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
|
||||
const REMOTE_READY_TIMEOUT_MS = 15_000;
|
||||
const REMOTE_REUSE_READY_TIMEOUT_MS = 2_000;
|
||||
|
||||
export interface RemoteT3RunnerOptions {
|
||||
readonly packageSpec?: string;
|
||||
@@ -241,37 +237,12 @@ function applyScriptPlaceholders(
|
||||
}
|
||||
|
||||
export function describeReadinessCause(cause: unknown): unknown {
|
||||
if (isSshReadinessError(cause)) {
|
||||
const base = {
|
||||
if (cause instanceof SshReadinessError) {
|
||||
return {
|
||||
_tag: cause._tag,
|
||||
message: cause.message,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
switch (cause._tag) {
|
||||
case "SshReadinessProbeFailedError":
|
||||
return {
|
||||
...base,
|
||||
requestUrl: cause.requestUrl,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
case "SshReadinessProbeTimedOutError":
|
||||
return {
|
||||
...base,
|
||||
requestUrl: cause.requestUrl,
|
||||
attempt: cause.attempt,
|
||||
probeTimeoutMs: cause.probeTimeoutMs,
|
||||
};
|
||||
case "SshReadinessTimedOutError":
|
||||
return {
|
||||
...base,
|
||||
baseUrl: cause.baseUrl,
|
||||
requestUrl: cause.requestUrl,
|
||||
timeoutMs: cause.timeoutMs,
|
||||
intervalMs: cause.intervalMs,
|
||||
probeTimeoutMs: cause.probeTimeoutMs,
|
||||
attempts: cause.attempts,
|
||||
...(cause.cause === undefined ? {} : { cause: describeReadinessCause(cause.cause) }),
|
||||
};
|
||||
}
|
||||
}
|
||||
if (cause instanceof Error) {
|
||||
return {
|
||||
@@ -715,9 +686,9 @@ export function buildRemoteLaunchScript(input?: RemoteT3RunnerOptions): string {
|
||||
T3_WAIT_READY_SCRIPT: stripTrailingNewlines(REMOTE_WAIT_READY_SCRIPT),
|
||||
T3_DEFAULT_REMOTE_PORT: String(DEFAULT_REMOTE_PORT),
|
||||
T3_REMOTE_PORT_SCAN_WINDOW: String(REMOTE_PORT_SCAN_WINDOW),
|
||||
T3_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_READY_TIMEOUT)),
|
||||
T3_REUSE_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_REUSE_READY_TIMEOUT)),
|
||||
T3_READY_PROBE_TIMEOUT_MS: String(Duration.toMillis(SSH_READY_PROBE_TIMEOUT)),
|
||||
T3_READY_TIMEOUT_MS: String(REMOTE_READY_TIMEOUT_MS),
|
||||
T3_REUSE_READY_TIMEOUT_MS: String(REMOTE_REUSE_READY_TIMEOUT_MS),
|
||||
T3_READY_PROBE_TIMEOUT_MS: String(SSH_READY_PROBE_TIMEOUT_MS),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -899,21 +870,20 @@ const readRemoteServerLogTail = Effect.fn("ssh/tunnel.readRemoteServerLogTail")(
|
||||
|
||||
export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(function* (input: {
|
||||
readonly baseUrl: string;
|
||||
readonly timeout?: Duration.Input;
|
||||
readonly interval?: Duration.Input;
|
||||
readonly probeTimeout?: Duration.Input;
|
||||
readonly timeoutMs?: number;
|
||||
readonly intervalMs?: number;
|
||||
readonly probeTimeoutMs?: number;
|
||||
readonly path?: string;
|
||||
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
|
||||
const timeout = Duration.fromInputUnsafe(input.timeout ?? Duration.seconds(30));
|
||||
const interval = Duration.fromInputUnsafe(input.interval ?? Duration.millis(100));
|
||||
const probeTimeout = Duration.fromInputUnsafe(input.probeTimeout ?? SSH_READY_PROBE_TIMEOUT);
|
||||
const timeoutMs = Duration.toMillis(timeout);
|
||||
const intervalMs = Duration.toMillis(interval);
|
||||
const probeTimeoutMs = Duration.toMillis(probeTimeout);
|
||||
const retryPolicy = Schedule.spaced(interval);
|
||||
const timeoutMs = input.timeoutMs ?? 30_000;
|
||||
const intervalMs = input.intervalMs ?? 100;
|
||||
const probeTimeoutMs = input.probeTimeoutMs ?? SSH_READY_PROBE_TIMEOUT_MS;
|
||||
const retryPolicy = Schedule.spaced(Duration.millis(intervalMs)).pipe(
|
||||
Schedule.take(Math.max(0, Math.ceil(timeoutMs / intervalMs))),
|
||||
);
|
||||
const requestUrl = new URL(input.path ?? "/", input.baseUrl).toString();
|
||||
const client = yield* HttpClient.HttpClient;
|
||||
const lastProbeFailure = yield* Ref.make<Option.Option<unknown>>(Option.none());
|
||||
const lastProbeFailure = yield* Ref.make<unknown>(null);
|
||||
let attempt = 0;
|
||||
|
||||
yield* Effect.logDebug("ssh.tunnel.httpReady.start", {
|
||||
@@ -930,12 +900,11 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
Effect.gen(function* () {
|
||||
attempt += 1;
|
||||
const responseOption = yield* effect.pipe(
|
||||
Effect.timeoutOption(probeTimeout),
|
||||
Effect.timeoutOption(Duration.millis(probeTimeoutMs)),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new SshReadinessProbeFailedError({
|
||||
new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
@@ -944,32 +913,30 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
onSome: Effect.succeed,
|
||||
onNone: () =>
|
||||
Effect.fail(
|
||||
new SshReadinessProbeTimedOutError({
|
||||
new SshReadinessError({
|
||||
message: `Backend readiness probe exceeded ${probeTimeoutMs}ms at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
attempt,
|
||||
probeTimeoutMs,
|
||||
cause: {
|
||||
kind: "probe-timeout",
|
||||
attempt,
|
||||
probeTimeoutMs,
|
||||
},
|
||||
}),
|
||||
),
|
||||
});
|
||||
}).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessProbeFailedError({
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.tapError((cause) =>
|
||||
Ref.set(
|
||||
lastProbeFailure,
|
||||
Option.some({
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
),
|
||||
Ref.set(lastProbeFailure, {
|
||||
attempt,
|
||||
cause: describeReadinessCause(cause),
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -979,15 +946,14 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
|
||||
const result = yield* readinessClient.execute(HttpClientRequest.get(requestUrl)).pipe(
|
||||
Effect.mapError((cause) =>
|
||||
isSshReadinessError(cause)
|
||||
cause instanceof SshReadinessError
|
||||
? cause
|
||||
: new SshReadinessProbeFailedError({
|
||||
: new SshReadinessError({
|
||||
message: `Backend readiness probe failed at ${requestUrl}.`,
|
||||
requestUrl,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
Effect.timeoutOption(timeout),
|
||||
Effect.timeoutOption(Duration.millis(timeoutMs)),
|
||||
);
|
||||
|
||||
return yield* Option.match(result, {
|
||||
@@ -1007,17 +973,11 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
|
||||
intervalMs,
|
||||
probeTimeoutMs,
|
||||
attempts: attempt,
|
||||
lastFailure: Option.getOrUndefined(lastFailure),
|
||||
lastFailure,
|
||||
});
|
||||
return yield* new SshReadinessTimedOutError({
|
||||
return yield* new SshReadinessError({
|
||||
message: `Timed out waiting ${timeoutMs}ms for backend readiness at ${input.baseUrl}.`,
|
||||
baseUrl: input.baseUrl,
|
||||
requestUrl,
|
||||
timeoutMs,
|
||||
intervalMs,
|
||||
probeTimeoutMs,
|
||||
attempts: attempt,
|
||||
...(Option.isSome(lastFailure) ? { cause: lastFailure.value } : {}),
|
||||
cause: lastFailure,
|
||||
});
|
||||
}),
|
||||
});
|
||||
@@ -1276,7 +1236,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
yield* Effect.raceFirst(
|
||||
waitForHttpReady({
|
||||
baseUrl: input.httpBaseUrl,
|
||||
timeout: SSH_READY_TIMEOUT,
|
||||
timeoutMs: SSH_READY_TIMEOUT_MS,
|
||||
}),
|
||||
exitFailure,
|
||||
).pipe(
|
||||
@@ -1336,7 +1296,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
|
||||
: child
|
||||
.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: Duration.toMillis(TUNNEL_SHUTDOWN_TIMEOUT),
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
})
|
||||
.pipe(Effect.ignore),
|
||||
),
|
||||
@@ -1580,7 +1540,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
[
|
||||
tunnelEntry.process.kill({
|
||||
killSignal: "SIGTERM",
|
||||
forceKillAfter: Duration.toMillis(TUNNEL_SHUTDOWN_TIMEOUT),
|
||||
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
|
||||
}),
|
||||
stopRemoteServer(
|
||||
tunnelEntry.target,
|
||||
@@ -1634,7 +1594,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
|
||||
remotePort: entry.remotePort,
|
||||
});
|
||||
const readinessExit = yield* Effect.exit(
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeout: Duration.seconds(2) }),
|
||||
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeoutMs: 2_000 }),
|
||||
);
|
||||
if (Exit.isSuccess(readinessExit)) {
|
||||
yield* Effect.logDebug("ssh.environment.tunnel.reused", {
|
||||
|
||||
Reference in new issue
Block a user