Skip to content

Commit

Permalink
fix(dashmate): container name is already in use (#2341)
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov authored Nov 21, 2024
1 parent 0d0f477 commit f36588a
Showing 1 changed file with 19 additions and 12 deletions.
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

0 comments on commit f36588a

Please sign in to comment.