Skip to content

Commit

Permalink
Remove manual docker daemon request unpiping
Browse files Browse the repository at this point in the history
  • Loading branch information
thgreasi committed Nov 9, 2023
1 parent 6f63f35 commit 1e08607
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions lib/build/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import * as fs from 'mz/fs';
import * as path from 'path';
import { Duplex } from 'stream';
import * as tar from 'tar-stream';
import type * as http from 'http';

// Import hook definitions
import * as Plugin from './plugin';
Expand Down Expand Up @@ -84,7 +83,6 @@ export default class Builder {
const failBuild = _.once((err: Error) => {
streamError = err;
dup.destroy(err);
cleanupDaemonStream?.();
return this.callHook(
hooks,
'buildFailure',
Expand All @@ -98,8 +96,6 @@ export default class Builder {
inputStream.on('error', failBuild);
dup.on('error', failBuild);

let cleanupDaemonStream: (() => void) | undefined;

const buildPromise = (async () => {
const daemonStream = await this.docker.buildImage(inputStream, buildOpts);

Expand All @@ -109,27 +105,10 @@ export default class Builder {
layers,
fromTags,
(err) => {
cleanupDaemonStream = () => {
if (
'req' in daemonStream! &&
daemonStream.req != null &&
typeof daemonStream.req === 'object' &&
'destroy' in daemonStream.req &&
typeof daemonStream.req.destroy === 'function'
) {
const req = daemonStream.req as http.ClientRequest;
if (!req.destroyed) {
req.destroy();
}
}
daemonStream.unpipe();
cleanupDaemonStream = undefined;
};
reject(err);
},
);
outputStream.on('error', (error: Error) => {
daemonStream.unpipe();
reject(error);
});
outputStream.on('end', () =>
Expand All @@ -144,7 +123,7 @@ export default class Builder {

// It is helpful for the following promises to run in parallel because
// buildPromise may reject sooner than the buildStream hook completes
// (in which case the stream is unpipe'd and destroy'ed), and yet the
// (in which case the stream is destroy'ed), and yet the
// buildStream hook must be called in order for buildPromise to ever
// resolve (as the hook call consumes the `dup` stream).
Promise.all([
Expand Down

0 comments on commit 1e08607

Please sign in to comment.