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

fix(server): close Firefox completely between specs on Windows #7106

Merged

Conversation

suryart
Copy link
Contributor

@suryart suryart commented Apr 22, 2020

Firefox is spawned differently than chrome. For Firefox, the .kill() does not actually close the instance running with the current profile from the arguments. It spawns a parent and a child process and runs the spec in the child process instance, while .kill() kills the child process, it leaves the parent process running, leading the next run to conflict with another spawned process(which fails for obvious reason) for the next spec execution.

User facing changelog

  • Fixed an issue where running multiple specs in cypress run on Windows could fail.

Additional details

Bug fix: Video recording fails as Firefox instance not closing at the end of the spec on Windows.
Bug fix: Failing to start new spec with Firefox as previous Firefox instance not closing at the end of the spec on Windows.

How has the user experience changed?

N/A

PR Tasks

  • Have tests been added/updated?
  • Has the original issue been tagged with a release in ZenHub?
  • [ na ] Has a PR for user-facing changes been opened in cypress-documentation?
  • [ na ] Have API changes been updated in the type definitions?
  • [ na ] Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 22, 2020

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.

@CLAassistant
Copy link

CLAassistant commented Apr 22, 2020

CLA assistant check
All committers have signed the CLA.

@jennifer-shehane jennifer-shehane marked this pull request as draft April 22, 2020 14:42
@jennifer-shehane jennifer-shehane changed the title [WIP] Issue 6392 Firefox instance close fix on windows Issue 6392 Firefox instance close fix on windows Apr 22, 2020
@jennifer-shehane
Copy link
Member

Hi, we're changing our contributing workflow to use Draft PRs instead of [WIP] in the title. I've converted this PR to a Draft PR and removed [WIP] from the title.

Please mark the PR as Ready for Review when you're ready for a Cypress team member to review the PR.

@flotwig
Copy link
Contributor

flotwig commented May 12, 2020

@suryart does this only apply on win32, confirmed? it seems that users are having similar issues on macOS and linux, although not everyone 🤔

@flotwig
Copy link
Contributor

flotwig commented May 13, 2020

ah, i get it, this only happens on windows because we have to use cmd.exe to spawn firefox, and firefox immediately detaches itself from cmd.exe which leads to proc.kill failing...

@suryart
Copy link
Contributor Author

suryart commented May 22, 2020

@suryart does this only apply on win32, confirmed? it seems that users are having similar issues on macOS and linux, although not everyone 🤔

Sorry for the delayed response. I see in the other comment that you've figured it's happening only on Windows(win32). The PR mentioned seems like the right approach to me. So, please feel free to close this PR if needed.

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.

Hey @suryart, thanks for the PR. I tried doing a different fix in #7336 but it didn't work, so we should continue with your approach.

This PR looks good so far. Please add some unit tests in firefox_spec.ts to ensure there is not a regression, address the comments, and it should be good to merge.

packages/server/lib/browsers/firefox.ts Outdated Show resolved Hide resolved
packages/server/lib/browsers/firefox.ts Outdated Show resolved Hide resolved
packages/server/lib/browsers/firefox.ts Outdated Show resolved Hide resolved
packages/server/lib/browsers/firefox.ts Outdated Show resolved Hide resolved
packages/server/lib/browsers/firefox.ts Outdated Show resolved Hide resolved
@suryart
Copy link
Contributor Author

suryart commented Jun 1, 2020

Hey @suryart, thanks for the PR. I tried doing a different fix in #7336 but it didn't work, so we should continue with your approach.

This PR looks good so far. Please add some unit tests in firefox_spec.ts to ensure there is not a regression, address the comments, and it should be good to merge.

Sure. Thank you for the reviews. I will update code according to the changes requested in a few weeks.

@flotwig
Copy link
Contributor

flotwig commented Jun 5, 2020

@suryart I'll try to finish this up today, so we can get the fix out with the release next week

@flotwig flotwig force-pushed the issue-6392-firefox-close-fix-on-windows branch 2 times, most recently from 32b6b9c to 69195c2 Compare June 5, 2020 17:07
@flotwig flotwig force-pushed the issue-6392-firefox-close-fix-on-windows branch from 69195c2 to 7567d97 Compare June 5, 2020 17:23
@cypress
Copy link

cypress bot commented Jun 5, 2020



Test summary

7876 1 130 0


Run details

Project cypress
Status Failed
Commit c00f6cd
Started Jul 10, 2020 2:49 PM
Ended Jul 10, 2020 2:55 PM
Duration 06:37 💡
OS Linux Debian - 10.1
Browser Multiple

View run in Cypress Dashboard ➡️


Failures

cypress/integration/commands/xhr_spec.js Failed
1 ... > sets err on log when caused by the XHR response

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


let parentPidFile = browserInstance.spawnargs[browserInstance.spawnargs.length - 1].split('\\')
let parentPidWithFilename = parentPidFile[parentPidFile.length - 1].split('-')
let parentPid = parentPidWithFilename[parentPidWithFilename.length - 1]
Copy link
Contributor

Choose a reason for hiding this comment

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

the pid here is actually the pid of the Cypress Electron process, which we don't want to kill

@flotwig
Copy link
Contributor

flotwig commented Jun 5, 2020

having some issues getting this to work, something doesn't like being killed:
image

@bhaskerchari
Copy link

@flotwig,

Any luck with the changes done and the approach you have taken? I have also tried various ways of killing firefox instance but getting the same error as you mentioned in the above comment.

@flotwig
Copy link
Contributor

flotwig commented Jun 29, 2020

@bhaskerchari not yet, for now you could probably disable video recording (video: false) to avoid this error.

@bhaskerchari
Copy link

@bhaskerchari not yet, for now you could probably disable video recording (video: false) to avoid this error.

@flotwig , Sorry just curious how does it work by disabling video recording (video: false) to avoid this error? What it has to do with Video recording? However I tried this option you suggested but still didn't work.

@flotwig flotwig changed the title Issue 6392 Firefox instance close fix on windows fix(server): close Firefox completely between specs on Windows Jul 9, 2020
@flotwig
Copy link
Contributor

flotwig commented Jul 9, 2020

@bhaskerchari I was able to work around the ECONNRESET error by handling foxdriver errors here: 111e09b

@bhaskerchari
Copy link

@bhaskerchari I was able to work around the ECONNRESET error by handling foxdriver errors here: 111e09b

@flotwig ,

Thank you for the update but any idea on when the fix may be released into the latest cypress version?

@flotwig
Copy link
Contributor

flotwig commented Jul 10, 2020

Thank you for the update but any idea on when the fix may be released into the latest cypress version?

Hopefully within the next release.

@flotwig flotwig marked this pull request as ready for review July 10, 2020 15:25
@flotwig flotwig requested review from kuceb, a team and flotwig and removed request for a team July 10, 2020 15:26
@flotwig flotwig requested review from bahmutov and removed request for flotwig July 10, 2020 18:03
@flotwig
Copy link
Contributor

flotwig commented Jul 15, 2020

@bahmutov now that cypress-io/cypress-example-kitchensink#436 is opened, can this be approved?

Copy link
Contributor

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

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

I think this can work, let's merge it into develop to test against Kitchensink via

- npm run test-if -- --repo cypress-example-kitchensink --command test:ci:record:windows:firefox

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.

Cypress could not connect to Firefox. Error: cannot open socket displayed at beginning of running spec
6 participants