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

console.log broken when script timeout #306

Open
bchabrier opened this issue Jul 24, 2020 · 2 comments
Open

console.log broken when script timeout #306

bchabrier opened this issue Jul 24, 2020 · 2 comments

Comments

@bchabrier
Copy link

Hello,

Thanks a lot first for this amazing module, well done!

I have a strange behaviour where a script timeout breaks console.log. Actually, I am adding console to a sandbox in order to print traces from inside the script. Everything works fine, but when the script times out, it seems it breaks console.log.

I have created a simple program to reproduce the issue:

const { VM, VMScript } = require('vm2');

let vm = new VM({
    timeout: 100,
    sandbox: { console: console } // add console in order to use console.log from the script
});

while (true) {
    try {
        vm.run("while (true) console.log('log inside script');"); // after some timeouts, this line does not print anymore
    } catch (err) {
        console.warn(err.message);
    }
    console.log('log in main still working'); // after some timeouts, this line does not print anymore
    console.error('error in main still working'); // this line print forever
}

Expected output:

log inside script
...
log inside script
Script execution timed out.
log in main still working
error in main still working
log inside script
...
log inside script
Script execution timed out.
log in main still working
error in main still working
...

Current output:

log inside script
...
log inside script
Script execution timed out.
error in main still working
Script execution timed out.
error in main still working
Script execution timed out.
error in main still working
Script execution timed out.
error in main still working
...

It shows that console.log in main is no more working after a couple of timeouts, while console.error is still working.

Am I doing something wrong, that breaks console.log?

@XmiliaH
Copy link
Collaborator

XmiliaH commented Aug 6, 2020

This seems to be a problem with console.log having problems with the timeout. There is currently nothing I know of what I could do to fix this.

@bchabrier
Copy link
Author

Thanks for the update.

I have checked that the issue actually shows up with the vm node module (see nodejs issue #34678)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants