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 child process killed with a signal #5810

Merged
merged 6 commits into from
Nov 27, 2019
Merged

Conversation

bahmutov
Copy link
Contributor

@bahmutov bahmutov commented Nov 27, 2019

User facing changelog

If the Test Runner child process is killed with a signal like SIGKILL or SIGBUS, the NPM CLI process shows an error and exits with non-zero code, no longer swallowing the error.

Additional details

Child Electron process could crash for some reason (like running out of memory) while running tests, and close. In that case the CLI parent process would receive code: null, signal: <name> which is different from successful exit code: 0, signal: null or a failded test exit code: 1, signal: null. But the CLI parent process would just do truthy check if (code) { reject ... } thus swallowing the crash.

How has the user experience changed?

The users should get better CI information, that no longer shows passing green build while the tests crashed in Electron browser.

PR Tasks

  • Have tests been added/updated?
  • Has the original issue been tagged with a release in ZenHub?

Local testing

  • run Cypress with npm start. This will start the GUI in global mode
  • find the PID of the process id with ps like this
68518 ttys000    0:00.26 npm  
68521 ttys000    0:00.35 node ./cli/bin/cypress open --dev --global
68522 ttys000    0:01.19 node /Users/gleb/git/cypress/scripts/start.js --cwd /Users/gleb/git/cypress 
68523 ttys000    0:04.56 /Users/gleb/git/cypress/packages/electron/dist/Cypress/Cypress.app/Contents/
68524 ttys000    0:00.31 /Users/gleb/git/cypress/packages/electron/dist/Cypress/Cypress.app/Contents/
68526 ttys000    0:00.62 /Users/gleb/git/cypress/packages/electron/dist/Cypress/Cypress.app/Contents/
  • kill the node /Users/gleb/git/cypress/scripts/start.js process like kill -9 68522
  • CLI should show the following error
The Test Runner received event exit with signal SIGKILL

Please search Cypress documentation for possible solutions:

https://on.cypress.io

Check if there is a GitHub issue describing this crash:

https://github.com/cypress-io/cypress/issues

Consider opening a new issue.

----------

Platform: darwin (16.7.0)
Cypress Version: 0.0.0

and the exit code should be non-zero

$ echo $?
1

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 27, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@cypress
Copy link

cypress bot commented Nov 27, 2019



Test summary

3517 0 45 0


Run details

Project cypress
Status Passed
Commit ab7bca3
Started Nov 27, 2019 7:53 PM
Ended Nov 27, 2019 7:57 PM
Duration 04:00 💡
OS Linux Debian - 9.8
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@bahmutov bahmutov changed the title WIP: catch child process killed with a signal catch child process killed with a signal Nov 27, 2019
Copy link
Contributor

@flotwig flotwig left a comment

Choose a reason for hiding this comment

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

Can you give me a pointer on how to reproduce this locally? I tried killing the Electron process spawned by npm run cypress:open, but Cypress still seems to exit with exit code 0...

Comment on lines +176 to +189
context('detects kill signal', function () {
it('exits with error on SIGKILL', function () {
this.spawnedProcess.on.withArgs('exit').yieldsAsync(null, 'SIGKILL')

return spawn.start('--foo')
.then(() => {
throw new Error('should have hit error handler but did not')
}, (e) => {
debug('error message', e.message)
snapshot(e.message)
})
})
})

Copy link
Contributor

Choose a reason for hiding this comment

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

@bahmutov I think it would be worth it to add an e2e test for this, since it involves multiple processes, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

would be tricky though, maybe not worth the time investment unless we have issues with this PR going forward

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not so sure e2e would be worth it

  • we don't have e2e tests for CLI right now
  • Node side (that one that delivers code: null, signal: <name> is pretty solid :)
  • we have only changed our handling, which is covered by the tests
  • finally, so far this has affected only very small number of our users I believe, otherwise we would hear about it again and again

cli/lib/exec/spawn.js Outdated Show resolved Hide resolved
Co-Authored-By: Zach Bloomquist <github@chary.us>
cli/lib/errors.js Outdated Show resolved Hide resolved
Co-Authored-By: Zach Bloomquist <github@chary.us>
@bahmutov
Copy link
Contributor Author

love the new wording, will pull and update snapshot

return spawn.start('--foo')
.then(() => {
throw new Error('should have hit error handler but did not')
}, (e) => {
Copy link
Member

Choose a reason for hiding this comment

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

the .catch() pattern is highly preferred over passing two arguments to .then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, in this case, catch would let false positive slide (we really want NOT to resolve). Ideally we would plug in https://www.chaijs.com/plugins/chai-as-promised/

return spawn.start('--foo').should.eventually.rejectWith(...)

avallete pushed a commit to avallete/cypress that referenced this pull request Nov 28, 2019
* WIP: catch child process killed with a signal

* unit test getError

* we don't need custom exit code

* Update cli/lib/exec/spawn.js

Co-Authored-By: Zach Bloomquist <github@chary.us>

* Update cli/lib/errors.js

Co-Authored-By: Zach Bloomquist <github@chary.us>

* update snapshots with wording
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.

CLI does not detect killed Electron process with SIGKILL, SIGBUS etc
3 participants