Skip to content

Commit a968481

Browse files
committed
Cache Docker accessibility state for 3 seconds
1 parent 9e22466 commit a968481

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,23 @@ import {
2121
} from './docker-tunnel-proxy';
2222
import { ensureDockerInjectionVolumeExists } from './docker-data-injection';
2323

24-
export const isDockerAvailable = () =>
25-
(async () => new Docker().ping())() // Catch sync & async setup errors
26-
.then(() => true)
27-
.catch(() => false);
24+
let dockerAvailableCache: Promise<boolean> | undefined;
25+
26+
export const isDockerAvailable = () => {
27+
if (dockerAvailableCache) return dockerAvailableCache;
28+
else {
29+
dockerAvailableCache = (async () => { // Catch sync & async setup errors
30+
await new Docker().ping()
31+
})()
32+
.then(() => true)
33+
.catch(() => false);
34+
35+
// Cache the resulting status for 3 seconds:
36+
setTimeout(() => { dockerAvailableCache = undefined; }, 3000);
37+
38+
return dockerAvailableCache;
39+
}
40+
}
2841

2942
const IPv4_IPv6_PREFIX = "::ffff:";
3043

0 commit comments

Comments
 (0)