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

"Invalid string length" and memory issues #33

Closed
adaphi opened this issue Mar 4, 2016 · 3 comments
Closed

"Invalid string length" and memory issues #33

adaphi opened this issue Mar 4, 2016 · 3 comments
Labels

Comments

@adaphi
Copy link

adaphi commented Mar 4, 2016

Hello,

We've been having issues where using mochawesome as a reporter causes the node process to run out of memory. We have a fairly large number of tests to run (~800), but when run with no reporter they work just fine.

After vastly reducing the number of tests (to ~40) I managed to get the following related error:

Problem with mochawesome: RangeError: Invalid string length
    at join (native)
    at Object.stringify (native)
    at stringify (/usr/lib/node_modules/mochawesome/node_modules/json-stringify-safe/stringify.js:5:15)
    at Runner.<anonymous> (/usr/lib/node_modules/mochawesome/lib/mochawesome.js:116:20)
    at emitNone (events.js:72:20)
    at Runner.emit (events.js:166:7)
    at /usr/lib/node_modules/mocha/lib/runner.js:791:12
    at /usr/lib/node_modules/mocha/lib/runner.js:644:9
    at next (/usr/lib/node_modules/mocha/lib/runner.js:284:14)
    at Immediate._onImmediate (/usr/lib/node_modules/mocha/lib/runner.js:320:5)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Reducing it further (to 12!) then works fine.

The problem seems to be that each hook in the allHooks part of the object being passed to stringify (lib/mochawesome.js:116) contains two circular references - stringify does detect some of this but it results in a huge amount of duplicated stuff in the output. This vastly multiplies the impact of having many hooks alongside tests with a large body of content. When running with a large number of tests, the process runs out of memory before it is able to produce the error.

Attached is a file that will reproduce the problem, at least on my machine. Since it's a memory issue YMMV! It's a bit contrived but the idea is simply to show how a large number of hooks, tests, or a large test code body all contribute. Making the code body smaller doesn't entirely solve the issue, it just prevents it from happening until the test count is higher.

Versions:
node v4.3.2
mocha 2.4.5
mochawesome 1.3.1
Running via command line.

Is this something fixable?

mochawesomeMemTest.zip

@adamgruber
Copy link
Owner

@adaphi Thanks for the detailed write up and example code. Very much appreciated. I'll take a look into this and see what I can do.

@adamgruber
Copy link
Owner

Published 1.3.2 to fix this.

@adaphi
Copy link
Author

adaphi commented Mar 4, 2016

Verified that this resolves the issue. Thanks @adamgruber for the quick fix!

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

No branches or pull requests

2 participants