Skip to content

Commit f36588a

Browse files
authored
fix(dashmate): container name is already in use (#2341)
1 parent 0d0f477 commit f36588a

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

packages/dashmate/src/listr/tasks/ssl/VerificationServer.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,36 @@ export default class VerificationServer {
9797

9898
await this.dockerPull(image);
9999

100-
try {
101-
this.container = await this.docker.createContainer(opts);
102-
} catch (e) {
103-
if (e.statusCode === 409) {
100+
let retries = 0;
101+
const MAX_RETRIES = 3;
102+
while (!this.container && retries <= MAX_RETRIES) {
103+
try {
104+
this.container = await this.docker.createContainer(opts);
105+
} catch (e) {
106+
// Throw any other error except container name conflict
107+
if (e.statusCode !== 409) {
108+
throw e;
109+
}
110+
111+
// Container name is already in use
112+
104113
// Remove container
105114
const danglingContainer = await this.docker.getContainer(name);
106-
107115
await danglingContainer.remove({ force: true });
108116

109117
try {
110118
await danglingContainer.wait();
111119
} catch (waitError) {
112-
// Skip error if container is already removed
113-
if (e.statusCode !== 404) {
114-
throw e;
120+
// Throw any other error except container not found
121+
if (waitError.statusCode !== 404) {
122+
throw waitError;
115123
}
116-
}
117124

118-
// Try to create a container one more type
119-
this.container = await this.docker.createContainer(opts);
125+
// Skip error if container is already removed
126+
}
120127
}
121128

122-
throw e;
129+
retries++;
123130
}
124131

125132
this.startedContainers.addContainer(opts.name);

0 commit comments

Comments
 (0)