Skip to content

Commit

Permalink
Secure dying
Browse files Browse the repository at this point in the history
  • Loading branch information
pvorb committed Feb 28, 2012
1 parent c993d08 commit fd46441
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ confdir(process.cwd(), 'conf', function (err, confdir) {
var log = fs.createWriteStream(logFile, { flags: mode });

var app = new require('api')(conf.protocol).Server();
process.on('TERM', die);

function die(err) {
// ignore errors when closing log file
try {
app.on('close', function () {
process.exit();
});
app.close();
log.closeSync(log);
} catch (err) {}
throw err;
} finally {
log.destroy();
if (err)
throw err;
}
}

// error handling
Expand Down

0 comments on commit fd46441

Please sign in to comment.