Script watchdog timer for Node.js
C++ Python
Switch branches/tags
Nothing to show
Latest commit 850ff7a May 2, 2013 @apaprocki Marked project obsolete.
Permalink
Failed to load latest commit information.
.gitignore Initial commit. Oct 7, 2012
.travis.yml Add Travis CI config. Oct 13, 2012
LICENSE
README.md Marked project obsolete. May 2, 2013
binding.gyp Initial commit. Oct 7, 2012
package.json Initial commit. Oct 7, 2012
scriptdog.cpp Initial commit. Oct 7, 2012
scriptdog.h Initial commit. Oct 7, 2012

README.md

OBSOLETE

This project is now obsolete and has been removed from npm. I modified Node itself to add a timeout parameter to calls within the vm module. This support landed in joyent/node@c081809344bd6e35c49a1c573b954583c0e3a27d.

Scriptdog

Configurable watchdog timer that interrupts V8 from executing Javascript code that is either stuck in an infinite loop or is just taking too long.

Installation

npm install scriptdog

Usage

var Scriptdog = require('scriptdog').Scriptdog;
var sd = new Scriptdog(1000);
while (true) {}

In the above example, the script would continue executing endlessly, but the Scriptdog timer expires after 1000ms and terminates execution of the endless loop.

The Scriptdog constructor takes one argument -- milliseconds until timeout. The object also exposes a dispose() function, which should always be called after successful execution.

var Scriptdog = require('scriptdog').Scriptdog;
var vm = require('vm');
var sd = new Scriptdog(1000);

vm.runInNewContext('var i = 0; while (i++ < 10000000) {}');

sd.dispose();

Implementation

When constructed, a thread is created which runs a separate libuv event loop with a timer set with the specified timeout value.

When the timer expires, V8::TerminateExecution is called to terminate execution inside the default Isolate.

When dispose() is called, or when the object is collected, the timer is cancelled, the loop is deleted, and the thread is joined.

License

MIT License