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

VM top level vars are lost after a few iterations #769

Closed
paleolitico opened this issue Feb 9, 2015 · 5 comments
Closed

VM top level vars are lost after a few iterations #769

paleolitico opened this issue Feb 9, 2015 · 5 comments
Labels
confirmed-bug Issues with confirmed bugs. vm Issues and PRs related to the vm subsystem.

Comments

@paleolitico
Copy link

We use a DSL to configure a system.
We load it with vm.
Sometimes, for debuging purposes, we use top level variables in the DSL,
that are read and modified by several functions.
After a few executions of these functions, modifications done by one function
is not seen by others.
Tested with iojs-1.1.0.
It doesn't happen with node-0.12.0.

The following code reproduces the bug in a simplified framework.

The DSL executor:

var vm = require('vm');
var fs = require('fs');

function include(script) {
  vm.runInContext(fs.readFileSync(script), ctxt, script);
}

var jobs = [];
function job(name, n, action) {
  jobs.push({name: name, times: n, action: action});
}

var sandbox = {
  console: console,
  job: job
};

var ctxt = vm.createContext(sandbox);

function load() {
  for (var i = 2; i < process.argv.length; i++) include(process.argv[i]);
}

function execute(jobs) {
  for (var i = 0; i < 2; i++) {
    for (var j = 0; j < jobs.length; j++) {
      var job = jobs[j];
      var times = job.times;
      var action = job.action;
      console.info("Executing " + job.name + " (" + times + ")");
      for (var k = 0; k < times; k++) {
        action();
      }
    }
  }
}

load();
execute(jobs);

A configuration script to give as argument

var n = 0;

job("Action 1", 1000, function() {
  n++;
});

job("Action 2", 1, function() {
  console.info("Action 2 output: " + n);
  n=0;
});

Executed with node-0.12.0 the result is as expected:

Executing Action 1 (1000)
Executing Action 2 (1)
Action 2 output: 1000
Executing Action 1 (1000)
Executing Action 2 (1)
Action 2 output: 1000

Executed with iojs-1.1.0 the result is

Executing Action 1 (1000)
Executing Action 2 (1)
Action 2 output: 517
Executing Action 1 (1000)
Executing Action 2 (1)
Action 2 output: 0

The value 517 differs on each execution.
I suppose it depends on the V8 optimization process.

Probably related to #548
and nodejs/node-v0.x-archive#9084

@vkurchatkin vkurchatkin added the vm Issues and PRs related to the vm subsystem. label Feb 9, 2015
@Fishrock123
Copy link
Contributor

cc @domenic

@Fishrock123
Copy link
Contributor

@domenic also this?

@domenic
Copy link
Contributor

domenic commented Jun 5, 2015

Haven't been able to test this with the new patches, but I didn't see any reason why the new patches would necessarily fix it. I still have a list of vm bugs to work on :)

@jasnell
Copy link
Member

jasnell commented Apr 2, 2016

is this still an issue?

@paleolitico
Copy link
Author

It seems solved in current node releases, both LTS and Stable.
I have tested old versions and the last with the bug was iojs-2.5.0 (V8 4.2.77.21).
In iojs-3.0.0 (V8 4.4.63.26) was already solved.

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants