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

Cannot read property '33038646' of null - karma-junit-reporter/index.js:93:22 #61

Closed
osherx opened this issue Sep 16, 2015 · 35 comments · Fixed by egis/build-tools#122
Closed

Comments

@osherx
Copy link

osherx commented Sep 16, 2015

reproduced here
https://github.com/el-net/bs_karma_eval

when run locally as:

karma start karma/lc.js

reproduction is inconsistent :-(

full error:


Missing error handler on `socket`.
TypeError: Cannot read property '30193015' of null
    at specSuccess.specSkipped.specFailure (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma-junit-reporter/index.js:93:22)
    at onSpecComplete (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/lib/reporters/base.js:78:12)
    at null.<anonymous> (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/lib/events.js:13:22)
    at emit (events.js:129:20)
    at onResult (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/lib/browser.js:216:13)
    at Socket.<anonymous> (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/lib/events.js:13:22)
    at Socket.emit (events.js:129:20)
    at Socket.onevent (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/node_modules/socket.io/lib/socket.js:330:8)
    at Socket.onpacket (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/node_modules/socket.io/lib/socket.js:290:12)
    at Client.ondecoded (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/node_modules/socket.io/lib/client.js:193:14)
    at Decoder.Emitter.emit (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20)
    at Decoder.add (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12)
    at Client.ondata (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/node_modules/socket.io/lib/client.js:175:18)
    at Socket.emit (events.js:107:17)
    at Socket.onPacket (/Users/osher/ws/POC/bs_karma_eval/node_modules/karma/node_modules/socket.io/node_modules/engine.io/lib/socket.js:99:14)
    at WebSocket.emit (events.js:129:20)

@osherx
Copy link
Author

osherx commented Sep 16, 2015

hmm. I noted that in some browsers, each time karma launches the browser - a new tab is added to the browser, so I end up running the test on the browser X times - and that could be the source of a race-condition:

It could be that one tab reported results and the test is closed, and then another tab opened to the karma server ends test and tries to report results.

I can propose two alternatives:
1 - hook on registering browsers, as opposed to hook on launched browsers.
Karma will accept any browser tab that opens onto it...
2 - if ending the test nulls the suites object - then it could not be accessed naively in the named line of karma-junit-reporter/index.js:93:22.
perhaps closing the test and nulling it should implement wiser checks.

@elicwhite
Copy link

This is flaking on us as well. We get a different number of course.

@TomaszScisloGS
Copy link

@osherx
Can you elaborate on the solutions that you proposed?

With the newest version 0.3.8 I get the following error:

29 12 2015 11:41:27.921:WARN [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
var suite = suites[browser.id]
^
TypeError: Cannot read property '72831859' of null
at [object Object].onBrowserComplete (h:\Projects\WDP\src\web\node_modules\karma-junit-reporter\index.js:102:23)
at [object Object]. (h:\Projects\WDP\src\web\node_modules\karma\lib\events.js:13:22)
at [object Object].emit (events.js:117:20)
at [object Object]._onTimeout (h:\Projects\WDP\src\web\node_modules\karma\lib\browser.js:50:15)
at Timer.listOnTimeout as ontimeout

@StanleyGoldman
Copy link

I was getting this error regularly in a file watcher scenario. It would work the first time but fail often on subsequent runs. So I did some simple debugging and I found there are three functions at play. onRunStart, onBrowserStart, onRunComplete; they are intended to execute in that order.

I found this error occurs when onRunComplete executes before onBrowserStart.
As soon as I took restartOnFileChange out of my config file. I stopped getting the error.

@StanleyGoldman
Copy link

Related: #20

@TomaszScisloGS
Copy link

@StanleyGoldman
I already have this in my karma-junit-reporter code: robrich@836f89f but this hasn't solved my problem.

Can you elaborate on restartOnFileChange flag I cannot find it in karma-junit-reporte plugin doc. Do you have it in karma.config?

Thanks!

@StanleyGoldman
Copy link

It's a karma setting that I put in my karma.conf.
Taking it out seemed to abate the issue.

@TomaszScisloGS
Copy link

Thanks @StanleyGoldman
I don't have this option enabled and I still get this error from time to time

@pfrandsen
Copy link

I get this error too at random times on our Jenkins server - updating to use karma 0.13.21 seems to have helped (updated other karma relate npm modules to lates versione too).

dschaller pushed a commit to dschaller/karma-junit-reporter that referenced this issue Feb 27, 2016
dschaller pushed a commit to dschaller/karma-junit-reporter that referenced this issue Feb 27, 2016
@mathiasmoeller
Copy link

+1

@ianwremmel
Copy link

Is #38 also related?

@johnament
Copy link

This is flaking for us as well.

@ghost
Copy link

ghost commented Apr 7, 2016

Encountered this issue after this update:
"karma-phantomjs-launcher": "^0.2.1" -> "karma-phantomjs-launcher": "^1.0.0"
"phantomjs": "^1.9.18" -> "phantomjs-prebuilt": "^2.1.7"

karma-junit version not changed and is 3.8.0

Bug reproduced on both linux (arch, ubuntu 14.04) and windows (10) with different bersions of node (4.2, 4.3) and npm (2.x, 3.x).

All tests are correct and karma works correctly without junit.

SUMMARY:
✔ 147 tests completed
[23:04:20] Finished 'test-single' after 8.9 s
07 04 2016 23:04:29.413:WARN [PhantomJS 2.1.1 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
/home/doc/lab/test/Source/Web/node_modules/karma-junit-reporter/index.js:102
    var suite = suites[browser.id]
                      ^

TypeError: Cannot read property '30530595' of null
    at onBrowserComplete (/home/doc/lab/test/Source/Web/node_modules/karma-junit-reporter/index.js:102:23)
    at null.<anonymous> (/home/doc/lab/test/Source/Web/node_modules/karma/lib/events.js:13:22)
    at emitOne (events.js:95:20)
    at emit (events.js:182:7)
    at null._onTimeout (/home/doc/lab/test/Source/Web/node_modules/karma/lib/browser.js:50:15)
    at tryOnTimeout (timers.js:224:11)
    at Timer.listOnTimeout (timers.js:198:5)

Karma launched using public js API:

gulp.task('test-single', ['strict-check', 'prepare-test-config', 'bundle-templates'], function(done) {
  var options = {
    configFile: __dirname + '/../karma.conf.js',
    singleRun: true,
    autoWatch: false,
  };
  var runner = new Karma(options, done);

  runner.start();
});

@Caradonna9
Copy link

I fixed the Disconnected (1 times), because no message in 10000 ms. problem by increasing the browserNoActivityTimeout setting in karma.config. The default value is 10000 but I found my browser (PhantomJS) was consistently closing due to the TypeError: Cannot read property '30530595' of null before the tests finished running. Increasing to 30000 solved the issue for me.

@shoesel
Copy link

shoesel commented Jun 30, 2016

I already reported it on the karma-runner-project, but maybe that was wrong: github-karma
Seems the error only occurs with the karma-junit-reporter:

PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 3281 of 3302 (skipped 21) SUCCESS (25.1 secs / 23.617 secs)
Missing error handler on 'socket'.
TypeError: Cannot read property '93062136' of null
  at onBrowserComplete (/PATH-TO/node_modules/karma-junit-reporter/index.js:120:23)
  at .<anonymous> (/PATH-TO/node_modules/karma/lib/events.js:13:22)
  at emitTwo (events.js:111:20)
  at emit (events.js:191:7)
  at onComplete (/PATH-TO/node_modules/karma/lib/browser.js:143:13)
  at Socket.<anonymous> (/PATH-TO/node_modules/karma/lib/events.js:13:22)
  at emitTwo (events.js:111:20)
  at Socket.emit (events.js:191:7)
  at Socket.onevent (/PATH-TO/node_modules/socket.io/lib/socket.js:335:8)
  at Socket.onpacket (/PATH-TO/node_modules/socket.io/lib/socket.js:295:12)
  at Client.ondecoded (/PATH-TO/node_modules/socket.io/lib/client.js:193:14)
  at Decoder.Emitter.emit (/PATH-TO/node_modules/component-emitter/index.js:134:20)
  at Decoder.add (/PATH-TO/node_modules/socket.io-parser/index.js:247:12)
  at Client.ondata (/PATH-TO/node_modules/socket.io/lib/client.js:175:18)
  at emitOne (events.js:96:13)
  at Socket.emit (events.js:188:7)
  at Socket.onPacket (/PATH-TO/node_modules/engine.io/lib/socket.js:101:14)
  at emitOne (events.js:96:13)
  at WebSocket.emit (events.js:188:7)
  at WebSocket.Transport.onPacket (/PATH-TO/node_modules/engine.io/lib/transport.js:104:8)
  at WebSocket.Transport.onData (/PATH-TO/node_modules/engine.io/lib/transport.js:115:8)
  at WebSocket.onData (/PATH-TO/node_modules/engine.io/lib/transports/websocket.js:76:30)
  at emitTwo (events.js:106:13)
  at WebSocket.emit (events.js:191:7)
  at Receiver.ontext (/PATH-TO/node_modules/ws/lib/WebSocket.js:816:10)
  at /PATH-TO/node_modules/ws/lib/Receiver.js:477:18
  at Receiver.applyExtensions (/PATH-TO/node_modules/ws/lib/Receiver.js:364:5)
  at /PATH-TO/node_modules/ws/lib/Receiver.js:466:14
  at Receiver.flush (/PATH-TO/node_modules/ws/lib/Receiver.js:340:3)
  at Receiver.opcodes.1.finish (/PATH-TO/node_modules/ws/lib/Receiver.js:482:12)
  at Receiver.expectHandler (/PATH-TO/node_modules/ws/lib/Receiver.js:451:33)
  at Receiver.add (/PATH-TO/node_modules/ws/lib/Receiver.js:95:24)
  at Socket.realHandler (/PATH-TO/node_modules/ws/lib/WebSocket.js:800:20)
  at emitOne (events.js:96:13)
  at Socket.emit (events.js:188:7)
  at readableAddChunk (_stream_readable.js:172:18)
  at Socket.Readable.push (_stream_readable.js:130:10)
  at TCP.onread (net.js:542:20)

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Disconnectedundefined

@WuDo
Copy link

WuDo commented Jul 7, 2016

+1

@stramel
Copy link

stramel commented Jul 22, 2016

karma-runner/karma#1292

@hypery2k
Copy link

seems to be related to usage of the karma-jasmine-html-reporter. If i exclude this reporter in karma everything is working

@elicwhite
Copy link

Mm. I've gotten this and never used the jasmine reporter.

@ianwremmel
Copy link

Same here. i use the mocha reporter, the junit reporter, and sometimes the coverage reporter.

@ibbatta
Copy link

ibbatta commented Nov 23, 2016

+1 Here

I use karma 1.3.0 and karma-junit-reporter 1.1.0

@mlc-mlapis
Copy link

The same for me with "karma-htmlfile-reporter".

I use "karma" 1.3.0 and "karma-htmlfile-reporter" 0.3.4 and "phantomjs" 2.1.7.

@randakar
Copy link
Contributor

randakar commented Dec 2, 2016

+1

This one is pretty annoying. We also use karma-junit-reporter and karma-jasmine, but no jasmine reporter.
Increasing that timeout appears to do nothing for us either.

@randakar
Copy link
Contributor

randakar commented Dec 2, 2016

Alright. A little poking around in index.js seems to confirm that this bug lives in the karma-junit-reporter.
Adding the following snippet in various places that the suites object is accessed seems to help.

if( suites == null )
suites = Object.create(null)

Basically initializing that thing if events fire in a different order.

randakar added a commit to randakar/karma-junit-reporter that referenced this issue Dec 2, 2016
See karma-runner#61 (comment) as for why.

What this mainly does is expose the real problem: onRunStart() firing out-of-order with the rest.
Looks like there are some races somewhere, but I'm not convinced the problem lies within karma-junit-test itself.

New error output:
---
Running "karma:unit" (karma) task
[D] Task source: C:\DATA\git\ymonitor-frontend\node_modules\grunt-karma\tasks\grunt-karma.js
Verifying property karma.unit exists in config...OK
File: [no files]
Options: background=false, client={}
02 12 2016 16:17:47.082:INFO [karma]: Karma v0.13.22 server started at http://localhost:8084/
02 12 2016 16:17:47.091:INFO [launcher]: Starting browser PhantomJS
02 12 2016 16:17:48.802:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Connected on socket NHQQtIYrup2fNrbRAAAA with id 58745719
Warning: Task "karma:unit" failed. Use --force to continue.
Error: Task "karma:unit" failed.
    at Task.<anonymous> (C:\DATA\git\ymonitor-frontend\node_modules\grunt\lib\util\task.js:205:15)
    at null._onTimeout (C:\DATA\git\ymonitor-frontend\node_modules\grunt\lib\util\task.js:241:33)
    at Timer.listOnTimeout (timers.js:92:15)

Aborted due to warnings.
---
@theBull
Copy link

theBull commented Dec 2, 2016

Any chance we can get a PR for this?

@thatmarvin
Copy link
Contributor

I can reproduce this consistently as described in #99 (comment). Fix #110 is already merged into master, see if that works for you?

@randakar
Copy link
Contributor

randakar commented Dec 3, 2016

I have that fix (#110). It doesn't help, unfortunately. Not sure why though.
I will have to look into it monday when I get back to work ;)

@robinj
Copy link

robinj commented Dec 3, 2016

@randakar did you check out the code from master, rather than doing an npm install as the code with the fix hasn't been released yet. I will also look into it on Monday as it seems to be blocking all of our mac users from running their unit tests.

Not sure if this helps anything, but we have about 100 devs on Windows 7 and eight Redhat CI boxes and none of them seem to have been affected by the latest occurrence of this bug.

@randakar
Copy link
Contributor

randakar commented Dec 3, 2016

Yes. I checked out master when I built that patch and tested it. I will need to do some vesting to verify various potential solutions though. I wonder what is happening exactly and why.

@randakar
Copy link
Contributor

randakar commented Dec 3, 2016

.. testing. Silly autocorrect.

@randakar
Copy link
Contributor

randakar commented Dec 5, 2016

Alright. Quick testing seems to indicate that the commit in master actually changes the behaviour in question.
So my quick-and-dirty patch isn't necessary to fix this.

Nonetheless, I'm still getting the error listed above, so I would not be surprised if something else breaks now due to things running concurrently.

Also, I will send a new PR to implement robinj's suggestion to initialize suites earlier. It doesn't hurt, the whole way it's initialized now is slower and doing it early makes it pretty much immune to races.

randakar added a commit to randakar/karma-junit-reporter that referenced this issue Dec 5, 2016
As karma-runner#61 (comment)
Minor cleanup. Doing it this way should be faster though (no constructor call overhead, less code to begin with).
dignifiedquire pushed a commit that referenced this issue Dec 5, 2016
As #61 (comment)
Minor cleanup. Doing it this way should be faster though (no constructor call overhead, less code to begin with).
dignifiedquire pushed a commit that referenced this issue Dec 6, 2016
As #61 (comment)
Minor cleanup. Doing it this way should be faster though (no constructor call overhead, less code to begin with).

* Release memory held by a testsuite after we're done with it.

When a test finishes and the result has been written out the reference to the testsuite in the suites object can be dropped.
Ideally we'd drop the reference from the array entirely but that involves recreating the array and *that* might race.
So instead we just make the testsuite object point to 'null'.
@wesleycho
Copy link
Member

wesleycho commented Dec 12, 2016

@dignifiedquire I think this can be closed out now given the latest 1.2.0 release - shall we close this?

@wesleycho
Copy link
Member

This should be fixed, going to close this - comment here if it appears again with 1.2.0+ and we can reinvestigate.

@nemoDreamer
Copy link

I'm still getting this error for onBrowserComplete firing after onRunComplete. It only happens when I also add the "coverage" reporter/plugin, possibly because some lag is getting exacerbated by the extra overhead?

@randakar
Copy link
Contributor

randakar commented Apr 5, 2017

As I've mentioned before: lots of modules have this problem. "var suites" got copied all over the place. I bet the coverage reporter has it's own incarnation of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.