Skip to content

Commit

Permalink
fix: correct bad propagation of exit signals (#7755)
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jun 22, 2020
1 parent 768da16 commit bf752f1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/server/lib/util/node_options.ts
Expand Up @@ -3,7 +3,7 @@ import debugModule from 'debug'

const debug = debugModule('cypress:server:util:node_options')

const NODE_OPTIONS = `--max-http-header-size=${1024 ** 2} --http-parser=legacy`
export const NODE_OPTIONS = `--max-http-header-size=${1024 ** 2} --http-parser=legacy`

/**
* If Cypress was not launched via CLI, it may be missing certain startup
Expand Down Expand Up @@ -63,8 +63,9 @@ export function forkWithCorrectOptions (): void {
{ stdio: 'inherit' },
)
.on('error', () => {})
.on('exit', (code) => {
process.exit(code)
.on('exit', (code, signal) => {
debug('child exited %o', { code, signal })
process.exit(code === null ? 1 : code)
})
}

Expand Down
8 changes: 7 additions & 1 deletion packages/server/test/scripts/run.js
Expand Up @@ -164,4 +164,10 @@ console.log(cmd)

const child = execa.shell(cmd, { env, stdio: 'inherit' })

child.on('exit', process.exit)
child.on('exit', (code, signal) => {
if (signal) {
console.error(`tests exited with signal ${signal}`)
}

process.exit(code === null ? 1 : code)
})
63 changes: 63 additions & 0 deletions packages/server/test/unit/node_options_spec.ts
@@ -0,0 +1,63 @@
import '../spec_helper'
import sinon from 'sinon'
import { expect } from 'chai'
import cp, { ChildProcess } from 'child_process'
import { EventEmitter } from 'events'
import * as nodeOptions from '../../lib/util/node_options'
import mockedEnv from 'mocked-env'

describe('NODE_OPTIONS lib', function () {
context('.forkWithCorrectOptions', function () {
let fakeProc: EventEmitter
let restoreEnv

beforeEach(() => {
restoreEnv = mockedEnv({
NODE_OPTIONS: '',
ORIGINAL_NODE_OPTIONS: '',
})
})

afterEach(() => {
restoreEnv()
})

it('modifies NODE_OPTIONS', function () {
process.env.NODE_OPTIONS = 'foo'
expect(process.env.NODE_OPTIONS).to.eq('foo')
sinon.stub(cp, 'spawn').callsFake(() => {
expect(process.env).to.include({
NODE_OPTIONS: `${nodeOptions.NODE_OPTIONS} foo`,
ORIGINAL_NODE_OPTIONS: 'foo',
})

return null as ChildProcess // types
})
})

context('when exiting', function () {
beforeEach(() => {
fakeProc = new EventEmitter()

sinon.stub(cp, 'spawn')
.withArgs(process.execPath, sinon.match.any, { stdio: 'inherit' })
.returns(fakeProc as ChildProcess)

sinon.stub(process, 'exit')
})

it('propagates exit codes correctly', function () {
nodeOptions.forkWithCorrectOptions()
fakeProc.emit('exit', 123)
expect(process.exit).to.be.calledWith(123)
})

// @see https://github.com/cypress-io/cypress/issues/7722
it('propagates signals via a non-zero exit code', function () {
nodeOptions.forkWithCorrectOptions()
fakeProc.emit('exit', null, 'SIGKILL')
expect(process.exit).to.be.calledWith(1)
})
})
})
})

4 comments on commit bf752f1

@cypress-bot

This comment was marked as off-topic.

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bf752f1 Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.9.0/win32-ia32/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.9.0/win32-ia32/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.9.0/win32-ia32/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.9.0/win32-ia32/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bf752f1 Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.9.0/win32-x64/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.9.0/win32-x64/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.9.0/win32-x64/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.9.0/win32-x64/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.9.0/appveyor-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-33671025/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on bf752f1 Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.9.0/darwin-x64/circle-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-373816/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.9.0/circle-develop-bf752f1b2ed805a22aba06388884a5405bb68a84-373676/cypress.tgz

Please sign in to comment.