Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/lib/actions/sandbox/process-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const OPENSHELL_SUPERVISOR_RELAY_CHANNEL_TIMED_OUT_STDERR = `Error: × code: '
│ relay failed: status: DeadlineExceeded, message: \\"relay channel timed
│ out\\", details: [], metadata: MetadataMap { headers: {} }"
`;
const OPENSHELL_RELAY_CHANNEL_DROPPED_STDERR = `Error: × code: 'The service is currently unavailable', message: "relay
│ channel dropped"
`;
const OPENSHELL_RELAY_TARGET_NOT_FOUND_STDERR = `Error: × code: 'The service is currently unavailable', message: "No such file
│ or directory (os error 2)"
`;
Expand Down Expand Up @@ -139,6 +142,33 @@ describe("recreated sandbox OpenShell readiness", () => {
expect(sleeps).toEqual([3]);
});

it("retries when OpenShell drops the replacement supervisor's reverse relay", () => {
const captureOpenshellImpl = vi
.fn()
.mockReturnValueOnce({
status: 1,
output: OPENSHELL_RELAY_CHANNEL_DROPPED_STDERR.trim(),
stdout: "",
stderr: OPENSHELL_RELAY_CHANNEL_DROPPED_STDERR,
})
.mockReturnValueOnce({ status: 0, output: "", stdout: "", stderr: "" });
const beforeProbe = vi.fn(() => true);
const sleeps: number[] = [];

expect(
waitForRecreatedSandboxOpenShellReady("recreated-box", {
beforeProbe,
captureOpenshellImpl,
intervalSeconds: 3,
sleepImpl: (seconds) => sleeps.push(seconds),
timeoutSeconds: 30,
}),
).toBe(true);
expect(beforeProbe).toHaveBeenCalledTimes(2);
expect(captureOpenshellImpl).toHaveBeenCalledTimes(2);
expect(sleeps).toEqual([3]);
});

it.each([
OPENSHELL_RELAY_TARGET_NOT_FOUND_STDERR,
OPENSHELL_RELAY_TARGET_REFUSED_STDERR,
Expand Down
5 changes: 5 additions & 0 deletions src/lib/actions/sandbox/process-recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ const OPENSHELL_SERVICE_UNAVAILABLE = "code: 'The service is currently unavailab
const OPENSHELL_RELAY_OPEN_TIMED_OUT = 'message: "relay open timed out"';
const OPENSHELL_SUPERVISOR_RELAY_DEADLINE = "supervisor relay failed: status: DeadlineExceeded";
const OPENSHELL_RELAY_CHANNEL_TIMED_OUT = "relay channel timed out";
const OPENSHELL_RELAY_CHANNEL_DROPPED = 'message: "relay channel dropped"';
const OPENSHELL_RELAY_TARGET_NOT_FOUND = 'message: "No such file or directory (os error 2)"';
const OPENSHELL_RELAY_TARGET_REFUSED = 'message: "Connection refused (os error 111)"';

Expand Down Expand Up @@ -633,13 +634,17 @@ function isRetryableOpenshellReRegistrationState(
error.includes(OPENSHELL_SERVICE_UNAVAILABLE) &&
error.includes(OPENSHELL_SUPERVISOR_RELAY_DEADLINE) &&
error.includes(OPENSHELL_RELAY_CHANNEL_TIMED_OUT);
const relayChannelDropped =
error.includes(OPENSHELL_SERVICE_UNAVAILABLE) &&
error.includes(OPENSHELL_RELAY_CHANNEL_DROPPED);
const relayTargetUnavailable =
error.includes(OPENSHELL_SERVICE_UNAVAILABLE) &&
(error.includes(OPENSHELL_RELAY_TARGET_NOT_FOUND) ||
error.includes(OPENSHELL_RELAY_TARGET_REFUSED));
return (
sessionUnavailable ||
relayChannelTimedOut ||
relayChannelDropped ||
relayTargetUnavailable ||
error.includes(OPENSHELL_RELAY_OPEN_TIMED_OUT)
);
Expand Down
Loading