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

FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory #36

Open
jasonkhanlar opened this issue Apr 10, 2022 · 1 comment

Comments

@jasonkhanlar
Copy link

jasonkhanlar commented Apr 10, 2022

const fs = require('fs');
const hash = require('hash.js')

async function main() {
  let data = await fs.promises.readFile('large126MBfile', { encoding: 'utf8' });
  console.log('before');
  let sha256 = hash.sha256().update(data).digest('hex');
  console.log('after');
}
main();

output is:

# node --max-old-space-size=67108864 test.js
before

<--- Last few GCs --->

[418310:0x5299b80]     1363 ms: Scavenge 867.2 (900.6) -> 867.2 (900.6) MB, 20.2 / 0.0 ms  (average mu = 0.984, current mu = 0.984) allocation failure 
[418310:0x5299b80]     1620 ms: Scavenge 1249.7 (1283.2) -> 1249.7 (1283.2) MB, 30.1 / 0.0 ms  (average mu = 0.984, current mu = 0.984) allocation failure 
[418310:0x5299b80]     2004 ms: Scavenge 1823.5 (1857.0) -> 1823.5 (1857.0) MB, 44.4 / 0.0 ms  (average mu = 0.984, current mu = 0.984) allocation failure 


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x13ad8f9]
Security context: 0x1ff9fbdc0921 <JSObject>
    1: toArray [0x185c4cec0df1] [/root/node_modules/hash.js/lib/hash/utils.js:~18] [pc=0x1bdd2c9cad7b](this=0x185c4cec0829 <Object map = 0x10a9e2ec3051>,0x07ae208c0121 <Very long string[131054357]>,0x1e42e08004b9 <undefined>)
    2: update [0x150c16f71df9] [/root/node_...

FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory

Writing Node.js report to file: report.20220409.203712.418310.0.001.json
Node.js report completed
 1: 0x9f1420 node::Abort() [node]
 2: 0x9f36e2 node::OnFatalError(char const*, char const*) [node]
 3: 0xb5865e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
 4: 0xb589d9 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
 5: 0xd064e5  [node]
 6: 0xcdf111  [node]
 7: 0xce0df2 v8::internal::Factory::NewUninitializedFixedArray(int) [node]
 8: 0xe518cf  [node]
 9: 0xe51b6d  [node]
10: 0x1003b8b v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x13ad8f9  [node]
Aborted (core dumped)
@jasonkhanlar
Copy link
Author

jasonkhanlar commented Apr 10, 2022

https://github.com/indutny/hash.js/blob/master/lib/hash/utils.js#L31

When i === 112613937, fail happens. This outputs "debug" one time for me (more if lower)

  if (i > 112613936) console.log('debug');

https://github.com/indutny/hash.js/blob/master/lib/hash/utils.js#L34

  if (i > 112613936) console.log('debug2');
          res[p++] = c;
  if (i > 112613936) console.log('debug3');

I see 'debug2' but no 'debug3'

Also it does not seem to be a memory issue because I can produce the same crash with node --max-old-space-size=828 test.js

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

No branches or pull requests

1 participant