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

If we cannot connect to Chrome via RDP we should re-launch the browser #6884

Closed
bahmutov opened this issue Mar 30, 2020 · 11 comments
Closed
Labels
browser: chrome stage: proposal 💡 No work has been done of this issue stale no activity on this issue for a long period

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Mar 30, 2020

Cypress v4.20

Sometimes we randomly get "Failed to connect to Chrome" error, like this
Screen Shot 2020-03-30 at 4 52 13 PM

Since the error is pretty random, I believe this is due to RDP port being blocked or some transient thing. We do retry to connect, allowing the browser to start, but seems in some cases the browser is completely unable to receive our connection.

I have come up with a way to simulate the situation in https://github.com/bahmutov/cypress-native-chrome-code-coverage-example/tree/change-rdp-port branch change-rdp-port. Its plugin replaces the RDP port Cypress wants with random number

// cypress/plugins/index.js
// on event 'before:browser:launch'
  // find how Cypress is going to control Chrome browser
  // and change the port number
  const rdp = 40000 + Math.round(Math.random() * 25000)
  console.log('plugin: new RDP port', rdp)
  // have to replace an item in the array without changing the reference
  launchOptions.args.forEach((arg, k) => {
    if (arg.startsWith('--remote-debugging-port')) {
      console.log('replacing "%s"', arg)
      launchOptions.args[k] = `--remote-debugging-port=${rdp}`
    }
  })

  console.log('updated browser arguments')
  console.log(launchOptions.args.join('\n'))

  return launchOptions

causing the same failure.

Screen Shot 2020-03-30 at 4 48 42 PM

Proposal: in this case, we should kill the browser process, pick new RDP port and try again.

@cypress-bot cypress-bot bot added the stage: proposal 💡 No work has been done of this issue label Mar 31, 2020
@jennifer-shehane jennifer-shehane added stage: proposal 💡 No work has been done of this issue and removed stage: proposal 💡 No work has been done of this issue labels Mar 31, 2020
@jennifer-shehane
Copy link
Member

You can recreate this if you open 2 instances of Cypress. Not sure it's relevant to what you're experimenting with, but it does annoy me. #5613

@flotwig
Copy link
Contributor

flotwig commented Mar 31, 2020

Do you think this is a port collision issue, or what?

I think that this might not be the best idea because of how new browser processes interact with existing browser processes. In the case of #5613, relaunching the browser would open up a new window in the existing browser session each time the browser is relaunched, which would be pretty undesirable behavior imo.

@bahmutov
Copy link
Contributor Author

bahmutov commented Mar 31, 2020 via email

@flotwig
Copy link
Contributor

flotwig commented Mar 31, 2020

That was my first thought, but then I remembered that (for Chromium, at least) it will only use the launched process to connect to the existing browser process and launch a window there, then exit. So closing the child process won't close the window it created in an existing session.

@bahmutov
Copy link
Contributor Author

bahmutov commented Mar 31, 2020 via email

@flotwig
Copy link
Contributor

flotwig commented Mar 31, 2020

In #5613's case it's having two copies of Cypress open that causes it. I've also seen GPO on Windows cause --user-data-dir to be ignored, so it launches in the users existing non-Cypress browser session.

Maybe it could make sense in CI only?

@bahmutov
Copy link
Contributor Author

bahmutov commented Mar 31, 2020 via email

@bahmutov
Copy link
Contributor Author

Another user just commented that the first spec ran fine on CI, but the second could not connect. Points in favor of first browser not shutting down correctly, preventing connecting when we spawn the browser again.

Maybe if we cannot connect, we could use https://github.com/sindresorhus/ps-list to see if Chrome is hanging around and try to kill it. Or do it by default after shutting down the browser, instead of assuming it has exited.

@jennifer-shehane
Copy link
Member

Yes, most recently I have seen this occur during cypress run in people's logs when there are multiple spec files in a run - never really happens on first open.

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 17, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser: chrome stage: proposal 💡 No work has been done of this issue stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests

4 participants