From fd4644109c4ed85188671606f533e276e80143b3 Mon Sep 17 00:00:00 2001 From: Paul Vorbach Date: Tue, 28 Feb 2012 15:59:58 +0100 Subject: [PATCH] Secure dying --- bin/api.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/api.js b/bin/api.js index 89bb14959..6950f1fab 100644 --- a/bin/api.js +++ b/bin/api.js @@ -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