Skip to content

Commit

Permalink
fix #2007: swallow write syscall errors on child
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 16, 2022
1 parent be8ad84 commit 0af35be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

More detail: The published package for esbuild's JS API is in CommonJS format, although the source code for esbuild's JS API is in ESM format. The original ESM code for esbuild's JS API has no export named `default` so using a default import like this doesn't work with Babel-compatible toolchains (since they respect the semantics of the original ESM code). However, it happens to work with node-compatible toolchains because node's implementation of importing CommonJS from ESM broke compatibility with existing conventions and automatically creates a `default` export which is set to `module.exports`. This is an unfortunate compatibility headache because it means the `default` import only works sometimes. This release tries to fix this by explicitly creating a self-referential `default` export. It now doesn't matter if you do `esbuild.build()`, `esbuild.default.build()`, or `esbuild.default.default.build()` because they should all do the same thing. Hopefully this means people don't have to deal with this problem anymore.

* Handle `write` errors when esbuild's child process is killed ([#2007](https://github.com/evanw/esbuild/issues/2007))

If you type Ctrl+C in a terminal when a script that uses esbuild's JS library is running, esbuild's child process may be killed before the parent process. In that case calls to the `write()` syscall may fail with an `EPIPE` error. Previously this resulted in an uncaught exception because esbuild didn't handle this case. Starting with this release, esbuild should now catch these errors and redirect them into a general `The service was stopped` error which should be returned from whatever top-level API calls were in progress.

* Update to Go 1.17.7

The version of the Go compiler used to compile esbuild has been upgraded from Go 1.17.6 to Go 1.17.7, which contains a few [compiler and security bug fixes](https://github.com/golang/go/issues?q=milestone%3AGo1.17.7+label%3ACherryPickApproved).
Expand Down
8 changes: 7 additions & 1 deletion lib/npm/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,20 @@ let ensureServiceIsRunning = (): Service => {

let { readFromStdout, afterClose, service } = common.createChannel({
writeToStdin(bytes) {
child.stdin.write(bytes);
child.stdin.write(bytes, err => {
// Assume the service was stopped if we get an error writing to stdin
if (err) afterClose();
});
},
readFileSync: fs.readFileSync,
isSync: false,
isBrowser: false,
esbuild: ourselves,
});

// Assume the service was stopped if we get an error writing to stdin
child.stdin.on('error', afterClose);

const stdin: typeof child.stdin & { unref?(): void } = child.stdin;
const stdout: typeof child.stdout & { unref?(): void } = child.stdout;

Expand Down

0 comments on commit 0af35be

Please sign in to comment.