Skip to content

Commit

Permalink
Start waiting for container exit on container start instead of end of…
Browse files Browse the repository at this point in the history
… attach

Workaround to the issue loosely described in apocas/dockerode#534
  • Loading branch information
davidreis97 committed Mar 19, 2020
1 parent cbaa725 commit 1cbc6a2
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions dockerfile-utils/src/dynamicAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,26 @@ export class DynamicAnalysis {
this.getPerformance();
this.getOS();
this.checkEnvVar();

container.wait((err, data) => {
this.sendProgress(true);
if (this.isDestroyed) {
return;
}
if (err) {
this.debugLog("ERROR GETTING CONTAINER EXIT CODE", err);
return;
}
this.log("CONTAINER CLOSED WITH CODE", data.StatusCode);
if (data.StatusCode != 0) {
this.addDiagnostic(DiagnosticSeverity.Error, this.dockerfile.getENTRYPOINTs()[0].getRange(), "Container Exited with code (" + data.StatusCode + ") - See Logs");
this.publishDiagnostics();
}
this.destroy();
});
});

container.attach({ stream: true, stdout: true, stderr: true }, (err, stream: Stream) => {
container.attach({stream: true, stdout: true, stderr: true}, (err, stream: Stream) => {
if (this.isDestroyed) {
this.sendProgress(true);
return;
Expand All @@ -199,25 +216,7 @@ export class DynamicAnalysis {
this.sendProgress(true);
}
stream.on('data', (data) => {
this.log("CONTAINER STDOUT", data);
});
stream.on('end', (_) => {
container.wait((err, data) => {
this.sendProgress(true);
if (this.isDestroyed) {
return;
}
if (err) {
this.debugLog("ERROR GETTING CONTAINER EXIT CODE", err);
return;
}
this.log("CONTAINER CLOSED WITH CODE", data.StatusCode);
if (data.StatusCode != 0) {
this.addDiagnostic(DiagnosticSeverity.Error, this.dockerfile.getENTRYPOINTs()[0].getRange(), "Container Exited with code (" + data.StatusCode + ") - See Logs");
this.publishDiagnostics();
}
this.destroy();
});
this.log(data);
});
});
});
Expand Down

0 comments on commit 1cbc6a2

Please sign in to comment.