Skip to content

Commit

Permalink
Don't listen for SIGPIPE
Browse files Browse the repository at this point in the history
SIGPIPE normally doesn't cause node to exit [1]. However, by registering
and unregistering a "SIGPIPE" event handler, the behavior changes and
node starts exiting when receiving SIGPIPE signals.

Because signal-exit listens for SIGPIPE, it causes programs to exit
when receiving SIGPIPE, whereas normally node programs not using
signal-exit should not exit when receiving SIGPIPE.

This changes signal-exit to not listen for SIGPIPE and tests that a
program using signal-exit will not exit due to SIGPIPE signals. The test
uses an existing test fixture (test/fixtures/sigpipe.js) that was not
previously being used.

See also #19.

[1] https://github.com/nodejs/node/blame/44aba1ab1c2656caf8f0f03a2f47b4c4b35aa4a2/doc/api/process.markdown#L243
  • Loading branch information
parshap authored and isaacs committed May 13, 2016
1 parent bdb83f1 commit 100163a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = [
'SIGILL',
'SIGINT',
'SIGIOT',
'SIGPIPE',
'SIGPROF',
'SIGQUIT',
'SIGSEGV',
Expand Down
9 changes: 9 additions & 0 deletions test/signal-exit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ describe('signal-exit', function () {
done()
})
})

it('does not exit on sigpipe', function (done) {
exec(process.execPath + ' ./test/fixtures/sigpipe.js', shell, function (err, stdout, stderr) {
assert.ifError(err)
stdout.should.match(/hello/)
stderr.should.match(/onSignalExit\(0,null\)/)
done()
})
})
})

0 comments on commit 100163a

Please sign in to comment.