Script watchdog timer for Node.js
C++ Python
Switch branches/tags
Nothing to show
Latest commit 850ff7a May 2, 2013 @apaprocki Marked project obsolete.
Failed to load latest commit information.
.gitignore Initial commit. Oct 7, 2012
.travis.yml Add Travis CI config. Oct 13, 2012
LICENSE 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


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.


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


npm install scriptdog


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) {}');



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.


MIT License