Commit f36588a 1 parent 0d0f477 commit f36588a Copy full SHA for f36588a
File tree 1 file changed +19
-12
lines changed
packages/dashmate/src/listr/tasks/ssl
1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -97,29 +97,36 @@ export default class VerificationServer {
97
97
98
98
await this . dockerPull ( image ) ;
99
99
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
+
104
113
// Remove container
105
114
const danglingContainer = await this . docker . getContainer ( name ) ;
106
-
107
115
await danglingContainer . remove ( { force : true } ) ;
108
116
109
117
try {
110
118
await danglingContainer . wait ( ) ;
111
119
} 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 ;
115
123
}
116
- }
117
124
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
+ }
120
127
}
121
128
122
- throw e ;
129
+ retries ++ ;
123
130
}
124
131
125
132
this . startedContainers . addContainer ( opts . name ) ;
You can’t perform that action at this time.
0 commit comments