Skip to content

Cannot close app gracefully with supervisor #96

Description

@binarykitchen

Hello Isaacs

Somehow the supervisor is giving me headaches with my own shutdown script. It never calls the timeout below:

    var graceTimeout;
    var gracefullyClosing = false;

    if (app.get('env') == 'development') {
        graceTimeout = 100;
    } else {
        graceTimeout = app.get('graceTimeout');
    }

    app.use(function (req, res, next) {
        if (gracefullyClosing) {
            console.info('gracefully refused a connection.');

            res.setHeader('Connection', 'close');
            res.send(502, 'server is in the process of restarting');
        } else
            next();
    });

    var closeGracefully = function(signal) {
        gracefullyClosing = true;

        console.info(
            'received signal (%s) on %s, shutting down gracefully in %s ms',
            signal,
            new Date().toString('T'),
            graceTimeout
        );

        setTimeout(function() {
            console.info(
                '(x) forcefully shutting down',
                graceTimeout
            );
            process.exit();
        }, graceTimeout);

        server.close(function() {
            console.info('all connections are ended');
        });
    };

    var signals = ['SIGINT', 'SIGTERM', 'SIGQUIT'];
    for (i in signals) {
        process.on(signals[i], function() {
            closeGracefully(signals[i]);
        });
    }

for production env the console shows:
received signal (SIGQUIT) on Fri Mar 15 2013 17:39:14 GMT+1300 (NZDT), shutting down gracefully in 10000 ms

but that's all. settimeout '(x) forcefully shutting down' is never called. is that because the supervisor is exiting before? it so, how come it's not reloading?

thanks for your help,
michael

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions