diff --git a/src/interceptors/docker/docker-interception-services.ts b/src/interceptors/docker/docker-interception-services.ts index 62b3d5e82..a1fa4bd17 100644 --- a/src/interceptors/docker/docker-interception-services.ts +++ b/src/interceptors/docker/docker-interception-services.ts @@ -21,14 +21,17 @@ import { stopDockerTunnel, } from './docker-tunnel-proxy'; import { ensureDockerInjectionVolumeExists } from './docker-data-injection'; +import { withTimeout } from '../../util/promise'; let dockerAvailableCache: Promise | undefined; +const DOCKER_AVAILABILITY_TIMEOUT_MS = 3_000; + export const isDockerAvailable = (options: { logError?: boolean } = {}) => { if (dockerAvailableCache) return dockerAvailableCache; else { dockerAvailableCache = (async () => { // Catch sync & async setup errors - return new Docker().info(); + return withTimeout(DOCKER_AVAILABILITY_TIMEOUT_MS, new Docker().info()); })() .then((info: { OSType?: 'windows' | 'linux' }) => { if (info.OSType === 'windows') { @@ -203,4 +206,4 @@ export async function deleteAllInterceptedDockerData(proxyPort: number | 'all'): delete pendingDeactivations[proxyPort]; })() ]) as Promise as Promise; -} \ No newline at end of file +} diff --git a/src/util/promise.ts b/src/util/promise.ts index 99ec6f9ba..cf4554f7d 100644 --- a/src/util/promise.ts +++ b/src/util/promise.ts @@ -23,8 +23,11 @@ export async function waitUntil( } export class TimeoutError extends CustomError { - constructor() { - super('Timeout', { code: 'timeout' }); + constructor(timeoutMs?: number) { + super( + timeoutMs === undefined ? 'Timeout' : `Timeout after ${timeoutMs}ms`, + { code: 'timeout' } + ); } } @@ -35,6 +38,6 @@ export async function withTimeout( return Promise.race([ promise, delay(timeoutMs, { unref: true }) - .then(() => { throw new TimeoutError(); }) + .then(() => { throw new TimeoutError(timeoutMs); }) ]); } \ No newline at end of file