Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle EPIPE on stdout gracefully #7194

Merged
merged 3 commits into from
Apr 19, 2019
Merged

Conversation

radhikalism
Copy link
Contributor

Problem: when yarn outputs to a pipe, it is sensitive to the pipe closing prematurely. If the pipe is closed before output is finished, a noisy error message appears on stderr.

It appears all commands with reporter output are affected. (yarn help appears to be unaffected, for example.)

Expected: yarn should handle the broken stdout pipe error quietly and complete its work (and exit with whatever status it would have otherwise).

To reproduce: trivial examples on node versions 8.x through 11.x, using head to truncate output before the last line:

$ yarn versions | head -n 16
yarn versions v1.15.2
{ yarn: '1.16.0-0',
  http_parser: '2.8.0',
  node: '8.15.1',
  v8: '6.2.414.75',
  uv: '1.23.2',
...
  tz: '2017c' }
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:868:14)
$ yarn versions | head -n 16
yarn versions v1.15.2
{ yarn: '1.16.0-0',
  http_parser: '2.8.0',
  node: '9.11.2',
  v8: '6.2.414.46-node.23',
  uv: '1.19.2',
...
  tz: '2018c' }
events.js:165
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:844:14)
Emitted 'error' event at:
    at onwriteError (_stream_writable.js:431:12)
    at onwrite (_stream_writable.js:453:5)
    at _destroy (internal/streams/destroy.js:39:7)
    at Socket.stdout._destroy (internal/process/stdio.js:19:7)
    at Socket.destroy (internal/streams/destroy.js:32:8)
    at WriteWrap.afterWrite [as oncomplete] (net.js:846:10)
$ yarn versions | head -n 31
yarn versions v1.15.2
{ yarn:
   '1.16.0-0',
  http_parser:
   '2.8.0',
  node:
   '10.15.3',
  v8:
   '6.8.275.32-node.51',
  uv:
   '1.23.2',
...
  tz:
   '2018e' }
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:779:14)
Emitted 'error' event at:
    at onwriteError (_stream_writable.js:431:12)
    at onwrite (_stream_writable.js:456:5)
    at _destroy (internal/streams/destroy.js:40:7)
    at Socket.dummyDestroy [as _destroy] (internal/process/stdio.js:11:34)
    at Socket.destroy (internal/streams/destroy.js:32:8)
    at WriteWrap.afterWrite [as oncomplete] (net.js:781:10)
$ yarn versions | head -n 35
yarn versions v1.15.2
{ yarn:
   '1.16.0-0',
  node:
   '11.13.0',
  v8:
   '7.0.276.38-node.18',
  uv:
   '1.27.0',
...
  unicode:
   '11.0' }
events.js:170
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:67:16)
Emitted 'error' event at:
    at errorOrDestroy (internal/streams/destroy.js:107:12)
    at onwriteError (_stream_writable.js:436:5)
    at onwrite (_stream_writable.js:461:5)
    at _destroy (internal/streams/destroy.js:49:7)
    at Socket.dummyDestroy [as _destroy] (internal/process/stdio.js:11:5)
    at Socket.destroy (internal/streams/destroy.js:37:8)
    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:68:12)

For comparison, npm (on node v11.13.0) behaves as expected:

$ npm version | head -n 15
{ yarn: '1.16.0-0',
  npm: '6.7.0',
...
  uv: '1.27.0',
  v8: '7.0.276.38-node.18',

This PR demonstrates a possible fix, which swallows pipe and stream errors on stdout without taking action, allowing yarn to complete quietly and exit as it would otherwise.

The correct behavior is visible like this (on node v11.13.0) for example:

$ yarn-local versions | head -n 35
yarn versions v1.16.0-0
{ yarn:
   '1.16.0-0',
  node:
   '11.13.0',
  v8:
   '7.0.276.38-node.18',
  uv:
   '1.27.0',
...
  unicode:
   '11.0' }

Please discuss.

@buildsize
Copy link

buildsize bot commented Apr 12, 2019

File name Previous Size New Size Change
yarn-[version].noarch.rpm 1.11 MB 1.11 MB 552 bytes (0%)
yarn-[version].js 4.48 MB 4.48 MB 233 bytes (0%)
yarn-legacy-[version].js 4.67 MB 4.67 MB 241 bytes (0%)
yarn-v[version].tar.gz 1.12 MB 1.12 MB 1.52 KB (0%)
yarn_[version]all.deb 816.87 KB 816.95 KB 84 bytes (0%)

@arcanis
Copy link
Member

arcanis commented Apr 19, 2019

Seems reasonable 👍

@arcanis arcanis closed this Apr 19, 2019
@arcanis arcanis reopened this Apr 19, 2019
@arcanis arcanis merged commit d4805c3 into yarnpkg:master Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants