Send Connection: close header on shut down

This commit is contained in:
Zaid Abdulla committed 2019-11-13 19:06:37 -08:00
1 parent 140acaa491
commit c66739c420
2 files changed
+22 -2

No files matched your search

+11 -1
View File
@@ -80,6 +80,8 @@ if (!cluster.worker) {
cert: config.get("FS_SSL_CERT") cert: config.get("FS_SSL_CERT")
}; };
let stopping = false;
process.on("uncaughtException", err => { process.on("uncaughtException", err => {
if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return; if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return;
logger.error({ logger.error({
@@ -87,15 +89,21 @@ if (!cluster.worker) {
exception: err, exception: err,
pid: process.pid pid: process.pid
}); });
stopping = true;
server server
.stop() .stop()
.then(exitWorkerGracefully) .then(exitWorkerGracefully)
.catch(exitWorkerUngracefully); .catch(exitWorkerUngracefully);
}); });
const _listener = (req, res): void => {
if (stopping) res.setHeader("Connection", "close");
listener(req, res);
};
const initPromise = Promise.all([db.connect(), cache.connect()]) const initPromise = Promise.all([db.connect(), cache.connect()])
.then(() => { .then(() => {
server.start(SERVICE_PORT, SERVICE_ADDRESS, ssl, listener); server.start(SERVICE_PORT, SERVICE_ADDRESS, ssl, _listener);
}) })
.catch(err => { .catch(err => {
setTimeout(() => { setTimeout(() => {
@@ -104,6 +112,7 @@ if (!cluster.worker) {
}); });
process.on("SIGINT", () => { process.on("SIGINT", () => {
stopping = true;
initPromise.finally(() => { initPromise.finally(() => {
server server
.stop() .stop()
@@ -113,6 +122,7 @@ if (!cluster.worker) {
}); });
process.on("SIGTERM", () => { process.on("SIGTERM", () => {
stopping = true;
initPromise.finally(() => { initPromise.finally(() => {
server server
.stop() .stop()
+11 -1
View File
@@ -84,6 +84,8 @@ if (!cluster.worker) {
cert: config.get("NBI_SSL_CERT") cert: config.get("NBI_SSL_CERT")
}; };
let stopping = false;
process.on("uncaughtException", err => { process.on("uncaughtException", err => {
if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return; if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return;
logger.error({ logger.error({
@@ -91,15 +93,21 @@ if (!cluster.worker) {
exception: err, exception: err,
pid: process.pid pid: process.pid
}); });
stopping = true;
server server
.stop() .stop()
.then(exitWorkerGracefully) .then(exitWorkerGracefully)
.catch(exitWorkerUngracefully); .catch(exitWorkerUngracefully);
}); });
const _listener = (req, res): void => {
if (stopping) res.setHeader("Connection", "close");
listener(req, res);
};
const initPromise = Promise.all([db.connect(), cache.connect()]) const initPromise = Promise.all([db.connect(), cache.connect()])
.then(() => { .then(() => {
server.start(SERVICE_PORT, SERVICE_ADDRESS, ssl, listener); server.start(SERVICE_PORT, SERVICE_ADDRESS, ssl, _listener);
}) })
.catch(err => { .catch(err => {
setTimeout(() => { setTimeout(() => {
@@ -108,6 +116,7 @@ if (!cluster.worker) {
}); });
process.on("SIGINT", () => { process.on("SIGINT", () => {
stopping = true;
initPromise.finally(() => { initPromise.finally(() => {
server server
.stop() .stop()
@@ -117,6 +126,7 @@ if (!cluster.worker) {
}); });
process.on("SIGTERM", () => { process.on("SIGTERM", () => {
stopping = true;
initPromise.finally(() => { initPromise.finally(() => {
server server
.stop() .stop()