isolated-vm
isolated-vm copied to clipboard
Basic code can crash the whole Node.js process
Here's a an example that causes an OOM and an ungraceful exit with isolated-vm:
const ivm = require("isolated-vm");
const isolate = new ivm.Isolate({memoryLimit: 512});
const context = isolate.createContextSync();
context.evalClosureSync(`
const arrayBuffer = new ArrayBuffer(100 * 1024 * 1024);
let view = new Array(arrayBuffer.byteLength);
let array = new Uint8Array(arrayBuffer);
let i = view.length;
while (i--) {
view[i] = array[i];
}
`);
Output:
<--- JS stacktrace --->
CALL_AND_RETRY_LAST
is_heap_oom = 1
<--- Heap statistics --->
total_heap_size = 203489280
total_heap_size_executable = 262144
total_physical_size = 201801728
total_available_size = 360626944
used_heap_size = 201638712
heap_size_limit = 562036736
malloced_memory = 49256
peak_malloced_memory = 254976
does_zap_garbage = 0
Abort trap: 6
Would appreciate some help in understanding whether this is a bug somewhere in isolated-vm or V8 and how a Node.js process can be more resilient against failures like this.
What's interesting here is that the used heap size is 200 MB (I am duplicating a 100 MB array buffer, so this seems expected). This is less than half of the memory limit, but we still have a heap OOM.
Yes that's a strange one. I don't have a solution for you at this time.