karma-runner / karma-chrome-launcher

A Karma plugin. Launcher for Chrome and Chrome Canary.
MIT License
469 stars 120 forks source link

ChromeHeadless 79.0.3945 disconnected on jenkins #218

Closed MDzyga closed 4 years ago

MDzyga commented 4 years ago

Hi, I have a problem with executing unit tests on jenkins.

Dependencies:

"@angular-devkit/build-angular": "^0.803.23",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.1",
"karma-jasmine": "~3.1.0",
"karma-jasmine-html-reporter": "^1.5.1",
"puppeteer": "^2.0.0",

My karma's configuration is:

const process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function (config) {
  config.set({
    basePath: '',
    browserNoActivityTimeout: 50000,
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 8080,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['ChromeHeadless'],
    singleRun: true,
    customLaunchers: {
      ChromeHeadless: {
        base: 'Chrome',
        flags: [
          '--headless',
          '--disable-gpu',
          '--remote-debugging-port=9222',
          '--no-sandbox',
          '--disable-dev-shm-usage'
        ]
      }
    }
  });
};

Error messages:

20 01 2020 13:54:20.183:INFO [karma-server]: Karma v4.4.1 server started at http://0.0.0.0:8080/
13:54:21 20 01 2020 13:54:20.191:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
13:54:21 20 01 2020 13:54:20.198:INFO [launcher]: Starting browser Chrome
13:54:59 20 01 2020 13:54:58.982:INFO [HeadlessChrome 79.0.3945 (Linux 0.0.0)]: Connected on socket XnNj1UhzUvpfZH5iAAAA with id 88283591
13:55:32 20 01 2020 13:55:31.108:WARN [HeadlessChrome 79.0.3945 (Linux 0.0.0)]: Disconnected (0 times)reconnect failed before timeout of 2000ms (ping timeout)
13:55:32 HeadlessChrome 79.0.3945 (Linux 0.0.0) ERROR
13:55:32   Disconnectedreconnect failed before timeout of 2000ms (ping timeout)
13:55:32 
13:55:32 HeadlessChrome 79.0.3945 (Linux 0.0.0) ERROR
13:55:32   Disconnectedreconnect failed before timeout of 2000ms (ping timeout)
lina128 commented 4 years ago

We are seeing same error message starting a week ago.

MDzyga commented 4 years ago

I resolved Disconnected issue by adding --source-map=false to script

MDzyga commented 4 years ago

but now sometimes I have this error:

09:18:54 HeadlessChrome 79.0.3945 (Linux 0.0.0): Executed 36 of 72 (skipped 14) SUCCESS (0 secs / 14.415 secs)
09:18:54 ERROR: '[2020-01-22T08:18:48.353Z] Error: Failed to complete negotiation with the server: Error'
johnjbarton commented 4 years ago

We started converting sourcemaps from inline to URL refs about six months ago because of browser failures on large test code.

The negotiation error is not from karma.

MDzyga commented 4 years ago

the negotiation error is related with @aspnet/signalr (1.1.4 version) package. This error occures only on jenkins

breautek commented 4 years ago

It's not limited to jenkins, seeing this error, just on my dev machine running Ubuntu 18, and my college using Mac OS X Catalina.

It happens very frequently, but sometimes all tests will run without disconnects for me. We've been run tests very often, so I'm fairly confident the issue only appears as of Chrome 79.0.3945

"karma": "4.4.1",
"karma-chrome-launcher": "3.1.0",

We started converting sourcemaps from inline to URL refs about six months ago because of browser failures on large test code.

My tests is running with inline sourcemaps, will change them over and report back results...

EDIT Changing my devtool config from inline-source-map to source-map or none doesn't appear to solve the problem for me.

breautek commented 4 years ago

For me, I've discovered the disconnect issue was actually due to flawed logic in my code base, where there was a memory leak of event listeners.

After karma disconnected from chrome, we noticed chrome was still going full throttle eating up 100% of the CPU, which led us to start commenting out unit tests until the problem went away. Eventually this led us to isolate the problem to one group of unit tests and eventually to a specific class in our code base.

Hope this helps some one.