Skip to content

Commit 52b4b3d

Browse files
authored
Merge pull request #220 from komen205/codex/docker-route-fail-open
Fail on stalled Docker route checks
2 parents 404ff8f + 9782f91 commit 52b4b3d

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/interceptors/docker/docker-interception-services.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ import {
2121
stopDockerTunnel,
2222
} from './docker-tunnel-proxy';
2323
import { ensureDockerInjectionVolumeExists } from './docker-data-injection';
24+
import { withTimeout } from '../../util/promise';
2425

2526
let dockerAvailableCache: Promise<boolean> | undefined;
2627

28+
const DOCKER_AVAILABILITY_TIMEOUT_MS = 3_000;
29+
2730
export const isDockerAvailable = (options: { logError?: boolean } = {}) => {
2831
if (dockerAvailableCache) return dockerAvailableCache;
2932
else {
3033
dockerAvailableCache = (async () => { // Catch sync & async setup errors
31-
return new Docker().info();
34+
return withTimeout(DOCKER_AVAILABILITY_TIMEOUT_MS, new Docker().info());
3235
})()
3336
.then((info: { OSType?: 'windows' | 'linux' }) => {
3437
if (info.OSType === 'windows') {
@@ -203,4 +206,4 @@ export async function deleteAllInterceptedDockerData(proxyPort: number | 'all'):
203206
delete pendingDeactivations[proxyPort];
204207
})()
205208
]) as Promise<unknown> as Promise<void>;
206-
}
209+
}

src/util/promise.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ export async function waitUntil<T extends unknown>(
2323
}
2424

2525
export class TimeoutError extends CustomError {
26-
constructor() {
27-
super('Timeout', { code: 'timeout' });
26+
constructor(timeoutMs?: number) {
27+
super(
28+
timeoutMs === undefined ? 'Timeout' : `Timeout after ${timeoutMs}ms`,
29+
{ code: 'timeout' }
30+
);
2831
}
2932
}
3033

@@ -35,6 +38,6 @@ export async function withTimeout<T>(
3538
return Promise.race([
3639
promise,
3740
delay(timeoutMs, { unref: true })
38-
.then(() => { throw new TimeoutError(); })
41+
.then(() => { throw new TimeoutError(timeoutMs); })
3942
]);
4043
}

0 commit comments

Comments
 (0)