From ddf9707e6b955260d929a55b26491ab02ba06753 Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Mon, 7 Oct 2019 13:19:03 -0400 Subject: [PATCH] Catch & ignore ENOTCONN errors when piping Cypress subprocess (#5293) * Catch & ignore ENOTCONN errors when piping Cypress subprocess * Update https-proxy-agent to point back to original repo --- cli/lib/exec/spawn.js | 3 ++- cli/test/lib/exec/spawn_spec.js | 30 +++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cli/lib/exec/spawn.js b/cli/lib/exec/spawn.js index 639a2ed88a96..a903bfafbbe2 100644 --- a/cli/lib/exec/spawn.js +++ b/cli/lib/exec/spawn.js @@ -179,13 +179,14 @@ module.exports = { } // https://github.com/cypress-io/cypress/issues/1841 + // https://github.com/cypress-io/cypress/issues/5241 // In some versions of node, it will throw on windows // when you close the parent process after piping // into the child process. unpiping does not seem // to have any effect. so we're just catching the // error here and not doing anything. process.stdin.on('error', (err) => { - if (err.code === 'EPIPE') { + if (['EPIPE', 'ENOTCONN'].includes(err.code)) { return } diff --git a/cli/test/lib/exec/spawn_spec.js b/cli/test/lib/exec/spawn_spec.js index b54a08e89860..2c9d36c2cec9 100644 --- a/cli/test/lib/exec/spawn_spec.js +++ b/cli/test/lib/exec/spawn_spec.js @@ -439,24 +439,28 @@ describe('lib/exec/spawn', function () { }) }) - it('catches process.stdin errors and returns when code=EPIPE', function () { - this.spawnedProcess.on.withArgs('close').yieldsAsync(0) + // https://github.com/cypress-io/cypress/issues/1841 + // https://github.com/cypress-io/cypress/issues/5241 + ;['EPIPE', 'ENOTCONN'].forEach((errCode) => { + it(`catches process.stdin errors and returns when code=${errCode}`, function () { + this.spawnedProcess.on.withArgs('close').yieldsAsync(0) - return spawn.start() - .then(() => { - let called = false + return spawn.start() + .then(() => { + let called = false - const fn = () => { - called = true - const err = new Error() + const fn = () => { + called = true + const err = new Error() - err.code = 'EPIPE' + err.code = errCode - return process.stdin.emit('error', err) - } + return process.stdin.emit('error', err) + } - expect(fn).not.to.throw() - expect(called).to.be.true + expect(fn).not.to.throw() + expect(called).to.be.true + }) }) })