@@ -92,52 +92,53 @@ const pendingDeactivations: {
92
92
// When a Docker container or the whole server shuts down, we do our best to delete
93
93
// every remaining intercepted image or container. None of these will be usable
94
94
// without us anyway, as they all depend on HTTP Toolkit for connectivity.
95
- export async function deleteAllInterceptedDockerData ( proxyPort : number | 'all' ) {
95
+ export async function deleteAllInterceptedDockerData ( proxyPort : number | 'all' ) : Promise < void > {
96
96
if ( pendingDeactivations [ proxyPort ] ) return pendingDeactivations [ proxyPort ] ;
97
97
if ( ! await isDockerAvailable ( ) ) return ;
98
98
99
- return pendingDeactivations [ proxyPort ] = ( async ( ) => {
100
- const docker = new Docker ( ) ;
101
-
102
- await stopDockerTunnel ( proxyPort ) ;
103
-
104
- const containers = await docker . listContainers ( {
105
- all : true ,
106
- filters : JSON . stringify ( {
107
- label : [
108
- proxyPort === 'all'
109
- ? DOCKER_CONTAINER_LABEL
110
- : `${ DOCKER_CONTAINER_LABEL } =${ proxyPort } `
111
- ]
112
- } )
113
- } ) ;
114
-
115
- await Promise . all ( containers . map ( async ( containerData ) => {
116
- const container = docker . getContainer ( containerData . Id ) ;
117
-
118
- // Best efforts clean stop & remove:
119
- await container . stop ( { t : 1 } ) . catch ( ( ) => { } ) ;
120
- await container . remove ( { force : true } ) . catch ( ( ) => { } ) ;
121
- } ) ) ;
122
-
123
- // We clean up images after containers, in case some containers depended
124
- // on some images that we intercepted.
125
- const images = await docker . listImages ( {
126
- all : true ,
127
- filters : JSON . stringify ( {
128
- label : [
129
- proxyPort === 'all'
130
- ? DOCKER_BUILD_LABEL
131
- : `${ DOCKER_BUILD_LABEL } =${ proxyPort } `
132
- ]
133
- } )
134
- } ) ;
135
-
136
- await Promise . all ( images . map ( async ( imageData ) => {
137
- await docker . getImage ( imageData . Id ) . remove ( ) . catch ( ( ) => { } ) ;
138
- } ) ) ;
139
-
140
- // Unmark this deactivation as pending
141
- delete pendingDeactivations [ proxyPort ] ;
142
- } ) ( ) ;
99
+ return pendingDeactivations [ proxyPort ] = Promise . all ( [
100
+ stopDockerTunnel ( proxyPort ) ,
101
+ ( async ( ) => {
102
+ const docker = new Docker ( ) ;
103
+
104
+ const containers = await docker . listContainers ( {
105
+ all : true ,
106
+ filters : JSON . stringify ( {
107
+ label : [
108
+ proxyPort === 'all'
109
+ ? DOCKER_CONTAINER_LABEL
110
+ : `${ DOCKER_CONTAINER_LABEL } =${ proxyPort } `
111
+ ]
112
+ } )
113
+ } ) ;
114
+
115
+ await Promise . all ( containers . map ( async ( containerData ) => {
116
+ const container = docker . getContainer ( containerData . Id ) ;
117
+
118
+ // Best efforts clean stop & remove:
119
+ await container . stop ( { t : 1 } ) . catch ( ( ) => { } ) ;
120
+ await container . remove ( { force : true } ) . catch ( ( ) => { } ) ;
121
+ } ) ) ;
122
+
123
+ // We clean up images after containers, in case some containers depended
124
+ // on some images that we intercepted.
125
+ const images = await docker . listImages ( {
126
+ all : true ,
127
+ filters : JSON . stringify ( {
128
+ label : [
129
+ proxyPort === 'all'
130
+ ? DOCKER_BUILD_LABEL
131
+ : `${ DOCKER_BUILD_LABEL } =${ proxyPort } `
132
+ ]
133
+ } )
134
+ } ) ;
135
+
136
+ await Promise . all ( images . map ( async ( imageData ) => {
137
+ await docker . getImage ( imageData . Id ) . remove ( ) . catch ( ( ) => { } ) ;
138
+ } ) ) ;
139
+
140
+ // Unmark this deactivation as pending
141
+ delete pendingDeactivations [ proxyPort ] ;
142
+ } ) ( )
143
+ ] ) as Promise < unknown > as Promise < void > ;
143
144
}
0 commit comments