Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashmate): container name is already in use #2341

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions packages/dashmate/src/listr/tasks/ssl/VerificationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,36 @@ export default class VerificationServer {

await this.dockerPull(image);

try {
this.container = await this.docker.createContainer(opts);
} catch (e) {
if (e.statusCode === 409) {
let retries = 0;
const MAX_RETRIES = 3;
while (!this.container && retries <= MAX_RETRIES) {
try {
this.container = await this.docker.createContainer(opts);
} catch (e) {
// Throw any other error except container name conflict
if (e.statusCode !== 409) {
throw e;
}

// Container name is already in use

// Remove container
const danglingContainer = await this.docker.getContainer(name);

await danglingContainer.remove({ force: true });

try {
await danglingContainer.wait();
} catch (waitError) {
// Skip error if container is already removed
if (e.statusCode !== 404) {
throw e;
// Throw any other error except container not found
if (waitError.statusCode !== 404) {
throw waitError;
}
}

// Try to create a container one more type
this.container = await this.docker.createContainer(opts);
// Skip error if container is already removed
}
}

throw e;
retries++;
}

this.startedContainers.addContainer(opts.name);
Expand Down
Loading