Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Ctrl+C not working #68

Closed
erikdubbelboer opened this issue Sep 23, 2015 · 4 comments
Closed

Ctrl+C not working #68

erikdubbelboer opened this issue Sep 23, 2015 · 4 comments

Comments

@erikdubbelboer
Copy link

When using time-grunt you can't Ctrl+C to kill grunt anymore. It just continues and ignores the event completely and exits when it's done.

Ubuntu 14.04.3 LTS
node v0.12.1
grunt-cli v0.1.13
grunt v0.4.5
@sindresorhus
Copy link
Owner

Can't reproduce. Are you sure it's time-grunt? Try upgrading Node.

@erikdubbelboer
Copy link
Author

I found the issue. Most tasks in grunt are synchronous. In our case our default task is a big synchronous task which does a lot of sync file IO (grunt.file.write etc).
In node when nothing catches SIGINT it just terminates the process immediately. But when time-grunt catches SIGINT node will dispatch the javascript code to run for it.
The problem is that our big task (any many others like grunt-uglify or grunt-contrib-cssmin) are all synchronous and don't yield for the SIGINT code to run.

This can be seen with this simple Gruntfile:

module.exports = function(grunt) {
  require('time-grunt')(grunt);

  grunt.registerTask('default', function() {
    console.log('testing...');
    var end = Date.now() + 4000;
    while (Date.now() < end) {
      grunt.file.write('test', 'test');
    }
    console.log('done');
  });
};

Try killing it with Ctrl+C and you'll see it only gets killed after the task completes. Now remove time-grunt to remove the SIGINT handler, try killing it again, and you'll see it is killed immediately.

So in conclusion: because most grunt tasks are written in a synchronous way there is nothing time-grunt can do about this issue. Except for maybe document this behavior.

@erikdubbelboer
Copy link
Author

erikdubbelboer commented Oct 2, 2015

I would suggest removing

time-grunt/index.js

Lines 147 to 149 in d850113

process.on('SIGINT', function () {
process.exit();
});
seeing as people who use Ctrl+C probably aren't interested in seeing the elapsed execution time anyways.

For now the workaround we're using is:

  var processOn = process.on;
  process.on = function(what,cb) {if(what!=='SIGINT'){processOn.call(process,what,cb);}};
  require('time-grunt')(grunt);
  process.on = processOn;

@sindresorhus
Copy link
Owner

Closing as this project is deprecated because Grunt is no longer actively maintained, so it doesn't make sense for me to maintain this project either.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants