From c7e8067551637616483e77e3045fb88c129eceec Mon Sep 17 00:00:00 2001 From: ivanshumkov Date: Thu, 21 Nov 2024 16:33:32 +0700 Subject: [PATCH 1/2] fix(dashmate): container name is already in use --- .../src/listr/tasks/ssl/VerificationServer.js | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js b/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js index eba5de00e4..197e3e079b 100644 --- a/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js +++ b/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js @@ -7,7 +7,7 @@ import { TEMPLATES_DIR } from '../../../constants.js'; export default class VerificationServer { /** * - * @param {Docker} docker + * @param {πDocker} docker * @param {dockerPull} dockerPull * @param {StartedContainers} startedContainers * @param {HomeDir} homeDir @@ -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); From b1d2e87948623cde573e0e4fd491f32d2606f5b1 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Thu, 21 Nov 2024 17:14:45 +0700 Subject: [PATCH 2/2] docs: fix Docker type --- packages/dashmate/src/listr/tasks/ssl/VerificationServer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js b/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js index 197e3e079b..0e7e584f35 100644 --- a/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js +++ b/packages/dashmate/src/listr/tasks/ssl/VerificationServer.js @@ -7,7 +7,7 @@ import { TEMPLATES_DIR } from '../../../constants.js'; export default class VerificationServer { /** * - * @param {πDocker} docker + * @param {Docker} docker * @param {dockerPull} dockerPull * @param {StartedContainers} startedContainers * @param {HomeDir} homeDir