cypress: New headless chrome randomly hangs at the end

Current behavior

Using new headless mode in Chrome it sometimes hangs after running test file (also mentioned in this comment https://github.com/cypress-io/cypress/issues/25972#issuecomment-1487021361)

Desired behavior

Consistent, correct behaviour just like with headless=old

Test code to reproduce

There is no simple repo to reproduce. From my observation it hangs mostly if test flow contains the page that has external (iframe) loaded content (in my case it’s google recaptcha). CI runs are more vulnerable to this issue, but I was able to reproduce it few times locally inside docker container.

Simple test code that sometimes fails:

describe('test_1', () => {
    it('Test test', () => {
        cy.visit('/login');// visit page that has reCaptcha loaded
        cy.get('img.deskop__logo').click();// click on main logo, get back to homepage
    });
});

Cypress Version

12.17.0

Node version

18.16.0

Operating System

Docker image: cypress/browsers:node-18.16.0-chrome-113.0.5672.92-1-ff-113.0-edge-113.0.1774.35-1

Debug Logs

Last few lines of good run (exited correctly):
  cypress:launcher:browsers chrome stderr: [0711/114213.126568:ERROR:nacl_helper_linux.cc(355)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly +831ms
  cypress:launcher:browsers chrome exited: { code: 0, signal: null } +1ms
  cypress:server:preprocessor removeFile /tests/files/test.ts +13s
  cypress:server:preprocessor base emitter plugin close event +0ms
  cypress:server:preprocessor base emitter native close event +2ms
  cypress:server:preprocessor base emitter native close event +0ms
  cypress:server:browsers:chrome closing remote interface client +416ms
  cypress:server:cypress about to exit with code 0 +19s
  cypress:webpack close /tests/files/test.ts +8s
  cypress:server:browsers browsers.kill called with no active instance +15s
  cypress:proxy:http:util:prerequests metrics: { browserPreRequestsReceived: 108, proxyRequestsReceived: 84, immediatelyMatchedRequests: 29, unmatchedRequests: 6, unmatchedPreRequests: 0 } +0ms
  cypress:cli child event fired { event: 'exit', code: 0, signal: null } +20s
  cypress:cli Stopping Xvfb +21s
  cypress:cli child event fired { event: 'close', code: 0, signal: null } +5ms

Last few lines of bad run (hangs):
  cypress:launcher:browsers chrome exited: { code: 0, signal: null } +1s
  cypress:server:preprocessor removeFile /tests/files/test.ts +18s
  cypress:server:preprocessor base emitter plugin close event +0ms
  cypress:server:preprocessor base emitter native close event +1ms
  cypress:server:preprocessor base emitter native close event +0ms
  cypress:server:browsers:chrome closing remote interface client +10ms
  cypress:webpack close /tests/files/test.ts +11s
  cypress:launcher:browsers chrome stderr: [0711/114246.895419:ERROR:nacl_helper_linux.cc(355)] NaCl helper process running without a sandbox!
Most likely you need to configure your SUID sandbox correctly +4ms

Other

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 6
  • Comments: 27 (8 by maintainers)

Most upvoted comments

This issue has been present as far back as v60 but got much worse in v112 (when we switched to the new headless=new), and has persisted all the way up to v121.0.6167.57 and beyond with some versions worse than others.

It’s intermittent and hard to verify sometimes, so many issues I’ve found about it on related projects have gotten closed as “cannot reproduce”. I’ve just confirmed it’s happening particularly consistently with v121 though, but I still can’t figure out why or when, as sometimes weird things like rebooting make it go away. I can post back here as I collect more reports on the latest versions.

There are also widespread reports of similar issues with the two telltale symptoms:

  • chrome headless seeems to hang indefinitely on exit sometimes
  • my [insert headless driver here] appears to have a memory leak (caused by chrome child processes hanging on exit and not releasing their memory)

Possibly related reports:

It’s possible some of these issues ^ are unrelated, but it’s also possible they all stem from the same underlying issue of child chromium processes not exiting correctly.

The problem is widespread enough that many of the tools that use chrome headless have implemented hacky workarounds like this: https://devforth.io/blog/how-to-simply-workaround-ram-leaking-libraries-like-puppeteer-universal-way-to-fix-ram-leaks-once-and-forever/ (spawning chrome under a child process then doing killasgroup -9 after every run)


I tried again just for fun and managed to reproduce this on the first try!

I didn’t even add any of the extra args we usually use (--disable-gpu, --no-sandbox, --disable-features=dbus, etc.), it hung immediately on the first try with only --headless=new and --screenshot!

Screenshot 2024-02-29 at 5 30 24 PM

This dispelled the last of my doubts, I think this is 100% an upstream Chromium bug and has nothing to do with Cypress/Playwright/Puppeteer/ArchiveBox/any driver.

I just opened an upstream bug report on the Chromium bug tracker, follow over there for progress: https://issues.chromium.org/issues/327583144 👾

htop

profiling1profiling2

We have the same issue, will there be a fix in the future?

--headless=old also worked for us.

We did notice that peak memory usage was around 3.5 GB with new, whereas old uses about 2.4 GB. Our github actions runner has a 4GB resource limit. Perhaps chrome is running out of memory and is making cypress hang (pure guess).

We are using the following github actions config:

  test:
    runs-on: [self-hosted, prod]
    container:
      image: cypress/included:cypress-13.2.0-node-20.6.1-chrome-116.0.5845.187-1-ff-117.0-edge-116.0.1938.76-1
      options: --ipc=host

and the following cypress.config.ts:

  e2e: {
    setupNodeEvents(_on, _config) {
      _on('before:browser:launch', (browser, launchOptions) => {
        if (browser.name === 'chrome') {
          launchOptions.args.push('--disable-dev-shm-usage');
          launchOptions.args.push('--headless=old');
        }
        console.log(launchOptions.args);
        return launchOptions;
      });
    },