Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Wrapper around `exec` that provides rolling timeout based on stdout/stderr activity.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
History.md
LICENSE
README.md
index.js
package.json
squawker

README.md

rolling_timeout_exec

Wrapper around child_process.exec that provides a rolling timeout based on stdout/stderr activity.

Goal

The goal of this package is to provide a practical way to tell the difference between a slow child process and a hung child process.

Changes

This package adds a new rollingTimeout option to exec.

rollingTimeout expects a numeric value representing the number of milliseconds to wait for activity from child processes before killing the child.

Activity means any output to stdout or stderr.

If a rollingTimeout is triggered, the child process is killed in the same way that timeout does, using options.killSignal and defaulting to SIGTERM. A rolling-timeout event is also emitted on the child process.

Usage

$ npm install rolling_timeout_exec
var exec = require('rolling_timeout_exec').exec,
    child,
    command,
    options,
    timeout = false;

command = 'git clone --progress http://some-slow-server.example.com/repo';
options = { rollingTimeout: 5000 };

child = exec(command, options, function (err, stdout, stderr) {
  if (err) {
    if (timeout) {
      console.error('timed out');
    }
    console.error(err.message, err.code);
    console.error(stdout);
    console.error(stderr);
  } else {
    console.log('git clone completed!');
  }
});

child.on('rolling-timeout', function () {
  timeout = true;
})

Test

Steps to run test suite:

$ cd ~/tmp
$ git clone https://github.com/alanning/rolling_timeout_exec.git
$ cd rolling_timeout_exec
$ npm install
$ npm test
Something went wrong with that request. Please try again.