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

Frequently repeating `(context).eval`ing with too short a timeout sometimes triggers `onCatastrophicError`.

Open issuefiler opened this issue 2 years ago • 1 comments

What I did

I wrote a simple Node.js module that creates a fresh V8 isolate, does this just once, and exits:

await execution_context.eval(
	/* a very long `string` of some obfuscated code
	   that takes about 30 milliseconds to run */,
	{timeout: 10} // milliseconds
);

And I executed the module (> node main.mjs) repeatedly with varying intervals, with my key and Enter key on the command prompt of my Windows 10.

The results

  • Most of the time, the node process immediately exited with Error: Script execution timed out.,
  • and sometimes it triggered the onCatastrophicError (that you provide to the Isolate constructor) with "Script failed to terminate" and hung forever unterminated.

Actually I’m not sure whether the frequent repetition or the timeout too short that was causing it. If I do EnterEnter (> node main.mjs) fast enough, it easily triggers the onCatastrophicError.

Might be related:

  • https://github.com/laverdet/isolated-vm/issues/156
  • https://github.com/laverdet/isolated-vm/issues/299

issuefiler avatar Apr 18 '22 18:04 issuefiler

I am also encountering this issue. It seems that the length of the timeout does not matter. It will crash regardless.

Most importantly it is not consistent. Please check the logs. Sometimes it crashes sometimes it does not.

Snippet:

const ivm = require('isolated-vm');

(async () => {
  const isolate = new ivm.Isolate({
    onCatastrophicError: (msg) => (console.log('onCatastrophicError', msg), process.abort()),
  });

  const context = await isolate.createContext();

  const moduleSrc = "while (true) {}";
  await context.eval(moduleSrc, {timeout: 1000});

  console.log('all ready')
})()

spec: Node v16.14.2 OS: Docker ubuntu:22.04 isolated-vm: 4.4.2

Here is the log:

root@localhost:~/workspace/app/tmp# node while-true-issue.js
onCatastrophicError Script failed to terminate
 1: 0xb09980 node::Abort() [node]
 2: 0xb7d1c9  [node]
 3: 0xd53d8e  [node]
 4: 0xd551af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
 5: 0x15f0bf9  [node]
Aborted (core dumped)
root@localhost:~/workspace/app/tmp# node while-true-issue.js
onCatastrophicError Script failed to terminate
 1: 0xb09980 node::Abort() [node]
 2: 0xb7d1c9  [node]
 3: 0xd53d8e  [node]
 4: 0xd551af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
 5: 0x15f0bf9  [node]
Aborted (core dumped)
root@localhost:~/workspace/app/tmp# node while-true-issue.js
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: Script execution timed out.
    at <isolated-vm>:1:1
    at (<isolated-vm boundary>)
    at /root/workspace/app/tmp/while-true-issue.js:11:17
root@localhost:~/workspace/app/tmp# node while-true-issue.js
onCatastrophicError Script failed to terminate
 1: 0xb09980 node::Abort() [node]
 2: 0xb7d1c9  [node]
 3: 0xd53d8e  [node]
 4: 0xd551af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
 5: 0x15f0bf9  [node]
Aborted (core dumped)
root@localhost:~/workspace/app/tmp# node while-true-issue.js
onCatastrophicError Script failed to terminate
 1: 0xb09980 node::Abort() [node]
 2: 0xb7d1c9  [node]
 3: 0xd53d8e  [node]
 4: 0xd551af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
 5: 0x15f0bf9  [node]
Aborted (core dumped)
root@localhost:~/workspace/app/tmp# node while-true-issue.js
onCatastrophicError Script failed to terminate
 1: 0xb09980 node::Abort() [node]
 2: 0xb7d1c9  [node]
 3: 0xd53d8e  [node]
 4: 0xd551af v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
 5: 0x15f0bf9  [node]
Aborted (core dumped)
root@localhost:~/workspace/app/tmp# node while-true-issue.js
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: Script execution timed out.
    at <isolated-vm>:1:1
    at (<isolated-vm boundary>)
    at /root/workspace/app/tmp/while-true-issue.js:11:17

EDIT: fixed formatting

SStoliarchuk avatar Feb 04 '23 20:02 SStoliarchuk