Skip to content

Commit af13258

Browse files
committed
Improve container cleanup process slightly
1 parent cb79315 commit af13258

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ export async function deleteAllInterceptedDockerData(proxyPort: number | 'all')
114114

115115
// Best efforts clean stop & remove:
116116
await container.stop({ t: 1 }).catch(() => {});
117-
await container.kill().catch(() => {});
118-
await container.remove().catch(() => {});
117+
await container.remove({ force: true }).catch(() => {});
119118
}));
120119

121120
// We clean up images after containers, in case some containers depended

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ export async function updateDockerTunnelledNetworks(
125125

126126
await containerMutex.runExclusive(async () => {
127127
// Inspect() must happen inside the lock to avoid any possible races.
128-
let container = await docker.getContainer(containerName).inspect();
128+
const container = await docker.getContainer(containerName).inspect()
129+
.catch(() => undefined);
130+
131+
if (!container) {
132+
// We checked this before, so if it's now missing again then we're probably in
133+
// some race where the tunnel & other containers are being stopped en masse, or
134+
// some odd shutdown condition. Not the end of the world - just skip this update.
135+
return;
136+
}
129137

130138
const expectedNetworks = _.uniq([
131139
...interceptedNetworks,
@@ -158,7 +166,7 @@ export async function updateDockerTunnelledNetworks(
158166

159167
// A map of proxy port (e.g. 8000) to the automatically mapped Docker tunnel port.
160168
// Refreshed if it's somehow missing, or on every call to ensureDockerTunnelRunning(), e.g.
161-
// async at every docker-proxy request & every container interception.
169+
// async at every docker-proxy request, every network event & every container interception.
162170
const portCache: { [proxyPort: string]: number | Promise<number> | undefined } = {};
163171

164172
export async function getDockerTunnelPort(proxyPort: number): Promise<number> {
@@ -228,8 +236,7 @@ export async function stopDockerTunnel(proxyPort: number | 'all'): Promise<void>
228236

229237
await Promise.all(containers.map(async (containerData) => {
230238
const container = docker.getContainer(containerData.Id);
231-
await container.kill().catch(() => {});
232-
await container.remove().catch(() => {});
239+
await container.remove({ force: true }).catch(() => {});
233240
}));
234241
});
235242
}

0 commit comments

Comments
 (0)