Skip to content

.create() destroys ability to listen to SIGINT #775

@sholladay

Description

@sholladay

It was driving me batty trying to figure out why I couldn't do a simple process.on('SIGINT', fn) in my build system. After a while I was finally able to pair the code down to a single method call: browserSync.create()

Here is a passing test case, for purpose of comparison (does not exhibit bad behavior).

var browserSync = require('browser-sync');

// Start reading from stdin so we don't exit, giving you time to
// send SIGINT manually via Control-C. You could substitute
// this with anything else that keeps Node running.
process.stdin.resume();

// Listen for signal that we should exit gracefully.
process.on('SIGINT', function () {
    console.log('Saw SIGINT.');
    process.exit(1);
});

And now, sadly, here is a failing test case (exhibits very bad behavior).

var browserSync = require('browser-sync').create();

process.stdin.resume();

process.on('SIGINT', function () {
    console.log('Saw SIGINT.');
    process.exit(1);
});

I noticed that a workaround is to register my SIGINT listener before creating the browserSync instance. This actually works.

var browserSync = require('browser-sync');

process.stdin.resume();

process.on('SIGINT', function () {
    console.log('Saw SIGINT.');
    process.exit(1);
});
bs.create();

😢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions