Skip to content

Commit 6a56265

Browse files
committed
Handle race conditions in Docker tunnel container restart
1 parent e74ab47 commit 6a56265

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/interceptors/docker/docker-tunnel-proxy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ export async function refreshDockerTunnelPortCache(proxyPort: number, { force }
231231
if (!localPort) {
232232
// This can happen if the networks of the container are changed manually, which can lose some
233233
// mappings, or if the container is being shut down. Kill & restart the container:
234-
await docker.getContainer(containerName).kill();
234+
await docker.getContainer(containerName).kill().catch((e) => {
235+
// If the container now doesn't exist/is stopped (due to a race condition) that's fine too:
236+
if (e.statusCode === 404 || e.statusCode === 409) return;
237+
else throw e;
238+
});
239+
235240
await ensureDockerTunnelRunning(proxyPort);
236241
await delay(10); // Wait for the port to bind after startup
237242
return refreshDockerTunnelPortCache(proxyPort, { force: true });

0 commit comments

Comments
 (0)