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

Catch & ignore ENOTCONN errors when piping Cypress subprocess #5293

Merged
merged 5 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/lib/exec/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
30 changes: 17 additions & 13 deletions cli/test/lib/exec/spawn_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
})

Expand Down