Skip to content

Commit

Permalink
fix(pacmak): occasional EISDIR failure (#948)
Browse files Browse the repository at this point in the history
There was a race condition in capturing the output of `npm pack`.
Ocassionally we would miss the output, not get a tarball name, combine
the empty string with a directory, and then get an EISDIR error when
trying to copy the tarball as a file (but giving it a directory name).

This race has been in there forever, but it became easier to trigger
since we started running a lot of `npm pack`s in parallel.

The solution is to wait for a different event on the `ChildProcess`
object.
  • Loading branch information
rix0rrr committed Nov 6, 2019
1 parent cb4057f commit a388f24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/jsii-pacmak/lib/packaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ export class JsiiModule {
// tarball name. otherwise, there can be a lot of extra noise there
// from scripts that emit to STDOUT.
const lines = out.trim().split(os.EOL);
return path.resolve(tmpdir, lines[lines.length - 1].trim());
const lastLine = lines[lines.length - 1].trim();

if (!lastLine.endsWith('.tgz') && !lastLine.endsWith('.tar.gz')) {
throw new Error(`npm pack did not produce tarball from ${this.moduleDirectory} into ${tmpdir} (output was ${JSON.stringify(lines)})`);
}

return path.resolve(tmpdir, lastLine);
});
}

Expand Down
5 changes: 4 additions & 1 deletion packages/jsii-pacmak/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export async function shell(cmd: string, args: string[], options: ShellOptions):
stderr.push(Buffer.from(chunk));
});
child.once('error', ko);
child.once('exit', (code, signal) => {

// Must use CLOSE instead of EXIT; EXIT may fire while there is still data in the
// I/O pipes, which we will miss if we return at that point.
child.once('close', (code, signal) => {
const out = Buffer.concat(stdout).toString('utf-8');
if (code === 0) { return ok(out); }
const err = Buffer.concat(stderr).toString('utf-8');
Expand Down

0 comments on commit a388f24

Please sign in to comment.