cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.05k stars 3.18k forks source link

Random failure [ERR_IPC_CHANNEL_CLOSED]: Channel closed #18127

Closed AndrewLeedham closed 1 year ago

AndrewLeedham commented 3 years ago

Current behavior

The last test in my cypress suite randomly fails in CI. It seems to be un-related to the test itself, but some cleanup failing.

Error logs

The following error was thrown by a plugin. We stopped running your tests because a plugin crashed. Please check your plugins file (`/home/runner/work/design-system/design-system/components/_cypress/plugins/index.js`)

 Error [ERR_IPC_CHANNEL_CLOSED] [ERR_IPC_CHANNEL_CLOSED]: Channel closed
    at ChildProcess.target.send (internal/child_process.js:705:16)
    at Object.send (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/plugins/util.js:32:25)
    at /home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/plugins/index.js:161:17
    at /home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/plugins/util.js:85:14
    at Promise.cancellationExecute [as _execute] (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/debuggability.js:406:9)
    at Promise._resolveFromExecutor (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:103:10)
    at Object.wrapParentPromise (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/plugins/util.js:63:12)
    at Object._get:task:body (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/plugins/index.js:146:23)
    at Object.execute (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/plugins/index.js:231:33)
    at /home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/task.js:53:22
    at tryCatcher (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at /home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/catch_filter.js:17:41
    at tryCatcher (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/runner/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:461:21)

plugins/index.js

const { startDevServer } = require('@cypress/webpack-dev-server');
// your project's webpack configuration
const webpackConfig = require('../webpack.config.js');

module.exports = (on, config) => {
  require('@cypress/code-coverage/task')(on, config);
  if (config.testingType === 'component') {
    on('dev-server:start', (options) => {
      return startDevServer({ options, webpackConfig });
    });
  }

  return config;
};

wepback.config.js

const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  resolve: {
    extensions: ['.js', '.ts', '.jsx', '.tsx'],
  },
  mode: 'development',
  devtool: false,
  output: {
    publicPath: '/',
    chunkFilename: '[name].bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        options: {
          presets: [
            '@babel/preset-typescript',
            '@babel/preset-env',
            ['@babel/preset-react', { runtime: 'automatic' }],
          ],
          plugins: [
            '@babel/plugin-proposal-class-properties',
            'babel-plugin-istanbul',
          ],
        },
      },
    ],
  },
  plugins: [
    new CopyWebpackPlugin({
      patterns: [{ from: '../../tools/storybook/static', to: '.' }],
    }),
  ],
  devServer: {
    stats: 'errors-only',
    noInfo: true,
  },
  stats: 'errors-only',
};

Desired behavior

Consistent test runs in CI. Or better error messages if this issue is something wrong with how I have things set up.

Test code to reproduce

I will try and create a repro when I get time.

Cypress Version

8.4.0

Other

CI errors are happening in GitHub actions, using the cypress run-ct command.

cypress version output:

Cypress package version: 8.4.0
Cypress binary version: 8.4.0
Electron version: 13.2.0
Bundled Node version: 14.16.0
AndrewLeedham commented 3 years ago

Doing some further digging, it seems like the last test is not able to load a local mp4 video. But it some times does and passes 😕 https://user-images.githubusercontent.com/5557458/133644099-b73a3b93-c7fa-41ea-b736-b6af35f9b72e.mp4

AndrewLeedham commented 3 years ago

So removing the tests with videos stops the error occurring. It seems to fail before it completes any of the video tests and when the it randomly passes it outputs the following:

| ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
| ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
| ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
| ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
| ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
| ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
| ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
| ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
| ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
| ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
| ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
| ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
| ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
| ALSA lib conf.c:4732:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
| ALSA lib conf.c:5220:(snd_config_expand) Evaluate error: No such file or directory
| ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default

So I am wondering if the random failure is to do with it looking for a graphics card, and that process is hanging for whatever reason.

Edit: Nope that's not it. I used echo -e 'pcm.!default {\n type hw\n card 0\n}\n\nctl.!default {\n type hw\n card 0\n}' > ~/.asoundrc from https://github.com/cypress-io/cypress/issues/4351#issuecomment-559489091 which suppressed the ALSA error, but the random IPC error still occurs.

AndrewLeedham commented 3 years ago

More error info from a failing run:

cypress:server:reporter got mocha event 'test:after:run' with args: [ { id: 'r2', order: 1, title: 'switches the video on different viewports', hookName: 'after each', err: { message: "Cannot destructure property 'data' of 'undefined' as it is undefined.\n" + '\n' + 'Because this error occurred during a `after each` hook we are skipping all of the remaining tests.', name: 'TypeError', stack: "TypeError: Cannot destructure property 'data' of 'undefined' as it is undefined.\n" + '\n' + 'Because this error occurred during a `after each` hook we are skipping all of the remaining tests.\n' + '    at /root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/lib/browsers/cdp_automation.js:253:34\n' + '    at tryCatcher (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)\n' + '    at Promise._settlePromiseFromHandler (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:547:31)\n' + '    at Promise._settlePromise (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:604:18)\n' + '    at Promise._settlePromise0 (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:649:10)\n' + '    at Promise._settlePromises (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/promise.js:729:18)\n' + '    at _drainQueueStep (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:93:12)\n' + '    at _drainQueue (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:86:9)\n' + '    at Async._drainQueues (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:102:5)\n' + '    at Immediate.Async.drainQueues [as _onImmediate] (/root/.cache/.yarn/.cypress/8.4.0/Cypress/resources/app/packages/server/node_modules/bluebird/js/release/async.js:15:14)\n' + '    at processImmediate (internal/timers.js:461:21)\n' }, state: 'failed', failedFromHookId: 'h6', body: 'function () {\n' + '  cy.mobile();\n' + '  cy.mount( /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_shared_XDSInternalWrapper__WEBPACK_IMPORTED_MODULE_0__["default"], {\n' + '    children: /*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_4__.jsx)(_Video_Video__WEBPACK_IMPORTED_MODULE_1__.Video, {\n' + '      src: {\n' + "        mobile: '/__cypress/src/videos/600x600.mp4',\n" + "        tablet: '/__cypress/src/videos/1200x450.mp4'\n" + '      },\n' + '      ratio: {\n' + '        mobile: [1, 1],\n' + '        tablet: [1200, 450]\n' + '      }\n' + '    })\n' + '  }));\n' + "  cy.get('video > source').should('have.attr', 'src', '/__cypress/src/videos/600x600.mp4');\n" + "  cy.get('video').should('have.length', 1);\n" + '  cy.desktop();\n' + "  cy.get('video').should('have.length', 1);\n" + "  cy.get('video > source').should('have.attr', 'src', '/__cypress/src/videos/1200x450.mp4');\n" + '}', type: 'test', duration: 60163, wallClockStartedAt: '2021-09-17T23:02:30.492Z', wallClockDuration: 60329, timings: { lifecycle: 12, 'before all': [Array], 'before each': [Array], test: [Object], 'after each': [Array] }, file: null, invocationDetails: { function: 'Object.getInvocationDetails', fileUrl: 'http://localhost:56535/__cypress/runner/cypress_runner.js', originalFile: 'http://localhost:56535/__cypress/runner/cypress_runner.js', line: 195314, column: 18, whitespace: '    ' }, final: true, currentRetry: 0, retries: 0 } ] +0ms

Which seems to be complaining about this line: https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/browsers/cdp_automation.ts#L320

Full test log: https://gist.github.com/AndrewLeedham/aa76487dd25e5195522cb90ac9a6761b

Interestingly disabling the screenshots with "screenshotOnRunFailure": false made code-coverage timeout. So I disabled code-coverage and that gave me a more typical timeout error: image

Any ideas why code-coverage would/could hide actual errors? Edit: It would seem that removing the failing test does not fix the IPC issue. So I believe this error is being caused by the @cypress/code-coverage/task plugin!

cypress-app-bot commented 1 year ago

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 commented 1 year ago

This issue has been closed due to inactivity.