npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tripwire

v4.1.0

Published

Break out from scripts blocking node.js event loop

Downloads

21

Readme

Tripwire

Tripwire allows node.js applications to termiante execution of scripts that block the node.js event loop. For example, you can break out from infinite loops like while(true). This functionality is useful if you are executing untrusted code within your node.js process.

Tripwire contains a native extension of node.js and currently supports Windows, Mac, and Linux. I do take contributions.

Install with:

npm install tripwire

Then in your application, you can put a limit on the total amout of CPU time (kernel and user mode combined) the event loop is blocked before the execution of the script is terminated:

var tripwire = require('tripwire');

process.on('uncaughtException', function (e) {
  console.log('The event loop was blocked for longer than 2000 milliseconds');
  process.exit(1);
});

// set the limit of execution time to 2000 milliseconds
tripwire.resetTripwire(2000);

// execute code that will block the event loop for longer
while(true);

// clear the tripwire (in this case this code is never reached)
tripwire.clearTripwire();

When the event loop is blocked for longer than the time specified in the call to resetTripwire, tripwire will terminate execution of the script. Node.js will subsequently execute the uncaughtException handler if one is registered. The exception passed to uncaughtException handler will be null in that case. In order to determine whether the exception was indeed caused by tripwire, an optional context can be established during a call to resetTripwire and retrtieved with a call to getContext. The getContext will return undefined if the tripwire had not been triggered.

var tripwire = require('tripwire');

process.on('uncaughtException', function (e) {
  if (undefined === tripwire.getContext())
    console.log('The exception was not caused by tripwire.');
  else
    console.log('The event loop was blocked for longer than 2000 milliseconds');
  process.exit(1);
});

// set the limit of execution time to 2000 milliseconds
var context = { someData: "foobar" };
tripwire.resetTripwire(2000, context);

For more samples, see here.

Running tests

There are a few mocha tests included that you can run with

mocha -R list

Building

On OSX and Linux, the native component is built at installation time.

On Windows, the native component is included in the repository and not built during npm install tripwire.

You can rebuild the native component using node-gyp. Currently the native component can be compiled on Windows, Mac, and Linux (I do take contributions).

On Windows:

node-gyp configure build
copy build\Release\tripwire.node lib\native\win32\4.0\ia32\