DependableSystemsLab / ThingsJS

ThingsJS is a framework for running JavaScript applications on IoT devices such as Raspberry PIs. For more details, see below:
http://thingsjs.io
MIT License
16 stars 5 forks source link

Migration causes failure if the specific code already exists on the engine code is migrating to #22

Closed marusshi closed 6 years ago

marusshi commented 6 years ago

Code Engine keeps track of all codes it is running in a field called codes, a mapping of the code name to Code object. When code migrates from engine n0 to n1, n1's codes field is updated to the code recovered from the snapshot

        var code = Code.fromSnapshot(kwargs.snapshot);
        self.codes[code.name] = code;

This will cause problems in an example like this:

  1. Code Engine n0 is running Foo.js
  2. Code Engine n1 is running Foo.js
  3. n1 migrates its Foo.js instance to n0
  4. n0's original Code object for Foo.js is overwritten and its reference is lost

This will specifically cause problems for the Scheduler because it assumes n0 still has reference to its original Foo.js. If the next schedule is computed where n0 should migrate its original Foo.js, an error like this will be thrown:

TypeError: Cannot read property 'snapshot' of undefined at Object.migrate_code (ThingsJS\lib\core\CodeEngine.js:269:69)
marusshi commented 6 years ago

I found a workaround for the SchedulerService class right now by running the code with unique code names for all components but this probably isn't optimal because it creates a new Code object every time instead of appending the new instance to the existing Code object.

jungkumseok commented 6 years ago

Fixed in 7f88ebd