isolated-vm icon indicating copy to clipboard operation
isolated-vm copied to clipboard

`memoryLimit` not being applied to isolate

Open davidjb opened this issue 11 months ago • 0 comments

Using the test code from https://github.com/laverdet/isolated-vm/blob/main/tests/catastrophic-error.js#L14, I'm testing as to the behaviour of OOM conditions. However, when running the following (e.g. just with node example.mjs), the memorySize limit isn't applied and the node process continues using 100% CPU and consuming memory until manually killed.

import ivm from 'isolated-vm';

for (const run of [
  context => context.eval('ivm.lib.testOOM()'),
]) {
  const isolate = new ivm.Isolate({
    memoryLimit: 128,
    onCatastrophicError: message => {
      console.log(message);
    },
  });
  const context = isolate.createContextSync();
  context.global.setSync('ivm', ivm);
  run(context);
}
Screenshot 2024-03-08 at 16 22 24

By comparison, running the example from https://github.com/laverdet/isolated-vm/?tab=readme-ov-file#examples behaves as the example shows, with the process ending with RangeError. Decreasing the memorySize in the example works - dropping the limit to 8MB sees the script end after 10MB.

Versions

  • isolated-vm v4.7.2
  • Node.js v21.6.2
  • gcc --version:
    Apple clang version 15.0.0 (clang-1500.1.0.2.5)
    Target: arm64-apple-darwin23.3.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    
  • macOS 14.3.1

davidjb avatar Mar 08 '24 06:03 davidjb