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

doc: document vm module limitation with timeouts and async code #8037

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions doc/api/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,28 @@ within which it can operate. The process of creating the V8 Context and
associating it with the `sandbox` object is what this document refers to as
"contextifying" the `sandbox`.

## Timeout limitation with asynchronous operations

There is a known limitation when using Promises with the `vm` methods that
allow for `timeout` option. Specifically: the `timeout` is only effective on
code run *within* the VM context; Promises, and other kinds of asynchronous
operations that execute outside of that scope are not limited by the callback.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... are not limited by the timeout


For instance, given the following script:

```js
vm.runInNewContext(
'Promise.resolve().then(()=>{while(1)console.log("foo", Date.now());});' +
'while(1)console.log(Date.now())',
{console:{log(){console.log.apply(console,arguments);}}},
{timeout:5}
);
```

The synchronous `while()` loop outside of the Promise is terminated by the
`timeout`, but the loop within the `Promise` continues to fire forever.


[indirect `eval()` call]: https://es5.github.io/#x10.4.2
[global object]: https://es5.github.io/#x15.1
[`Error`]: errors.html#errors_class_error
Expand Down