cypress: Cypress run won’t finish, stuck while making connection to Chrome

Current behavior:

I’m getting error: Cypress failed to make a connection to the Chrome DevTools Protocol after retrying during my tests. Usually happens during one of last tests (probably the last). I have multiple Cypress projects, happens on all of them. Tests are running in parallel, on Chrome.

Test code to reproduce

Issue happens quite randomly, I’m sorry, but I cannot really give a reproducible example, since this happens in CI only. Sending screenshots.

Snímka obrazovky 2020-02-24 o 9 24 54 Snímka obrazovky 2020-02-24 o 9 24 46

Versions

Cypress 4.0.2 CI: Bitbucket Pipelines Image: cypress/browsers:node13.6.0-chrome80-ff72

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 9
  • Comments: 42 (6 by maintainers)

Most upvoted comments

I assume that this problem is a copy of #7450. I solved my problem by adding the following workaround provided by @stevejefferies.

Should have added to my comment above, for those looking for a potential workaround adding the disable-gpu flag on browser launch (plugins/index.js) seems stable for me at least locally: Cypress 4+:

module.exports = (on, config) => {
  on('before:browser:launch', (browser, launchOptions) => {
    if (browser.name === 'chrome' && browser.isHeadless) {
      launchOptions.args.push('--disable-gpu');
      return launchOptions
    }
  });
}

Or before Cypress 4:

module.exports = (on, config) => {
  on('before:browser:launch', (browser, args) => {
    if (browser.name === 'chrome' && browser.isHeadless) {
      args.push(
        '--disable-gpu'
      );
      return args;
    }
  });
}

To run all test in edge without problems, you have to extend the if condition by adding the following:

browser.name === ‘edge’

Now, tests are running fine in chrome as well as in egde using headless mode.

I was missing the line

127.0.0.1 localhost in my /etc/hosts file. Afterwards it worked perfectly!

@tipsey same config . how to fix it ?

@simisimon That doesn’t work for me, unfortunately

Well, for me it just started to work magically without changing anything. During the period of time when cypress was not working with Chrome I have used Brave and everything was fine.

@simisimon !!! now we can finally run in chrome! every test file now runs 10-20 seconds faster THX 👍 🥇

Hey @jennifer-shehane thank you for taking a look into it. I have been experiencing this lot less recently, but I can’t put my finger down on what might have caused this.

to answer your questions:

  • yes, our runs usually have around 15 specs on each machine, 10 machines in total
  • each machine runs for about 8 to 10 minutes
  • no, I haven’t seen this on first spec ever. it was always on the last test of very last spec on very last machine

I’ll make sure to run with a debug if it might happen in close future

@79it You can modify the launch args sent to Chrome by following the instructions here: https://on.cypress.io/browser-launch-api#Modify-browser-launch-arguments

I’ve reviewed the comments/logs here and have not found many commonalities between the environments across people reporting this problem. A couple of things that are common:

  1. All running in Chrome headless
  2. Reported in Cypress versions 4+
  3. Error appears after running a large number of spec files?

I haven’t fully verified the 3rd assertion, but from the few logs provided, they all indicated that the error occurred after a large number of spec files ran (38+).

Some questions:

Please if you can answer the questions below if you’re experiencing this issue.

  • How many spec files run on a single machine until this error occurs?
  • How much time does cypress run on the single machine until this error occurs?
  • Has anyone ever seen this error on the first specfile launch?

I guess my theory is that this may be related to longer runs or runs that connect to the CDP several times over several spec files.

Also, tracking these debug logs specifically may be helpful in seeing if any leftover processes haven’t existed properly. DEBUG=cypress:*,cypress-verbose:server:util:process_profiler

@jennifer-shehane

Reporting in, I’m running into the same issue. using WSL 2 on Windows

`Title: Error launching browser

Message: Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 20 seconds.

This usually indicates there was a problem opening the Chrome browser.

The CDP port requested was <span class="ansi-yellow-fg">36647</span>.

Error details:

Error: connect ECONNREFUSED 127.0.0.1:36647 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14)

Stack trace:

Error: Cypress failed to make a connection to the Chrome DevTools Protocol after retrying for 20 seconds.

This usually indicates there was a problem opening the Chrome browser.

The CDP port requested was 36647.

Error details:

Error: connect ECONNREFUSED 127.0.0.1:36647
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14)

    at get (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/lib/errors.js:344:11)
    at Object.throwErr [as throw] (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/lib/errors.js:359:11)
    at /home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/lib/browsers/protocol.js:95:17
    at tryCatcher (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/adomyaty/.cache/Cypress/4.1.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

Let me know if DEBUG is needed as well and I can provide. FYI this problem only happens when running chrome. Headless works fine. I had this problem since Cypress 3.8 or so after upgrading to 4.1 issue still persists. It working before 3.8 as far as I recall