chore: Improve graceful server shutdown (#4625)
* chore: Improve graceful server shutdown * Replace node timers with custom promise timeout
This commit is contained in:
@@ -6,6 +6,7 @@ import Koa from "koa";
|
||||
import WebSocket from "ws";
|
||||
import { DocumentValidation } from "@shared/validations";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import ShutdownHelper, { ShutdownOrder } from "@server/utils/ShutdownHelper";
|
||||
import AuthenticationExtension from "../collaboration/AuthenticationExtension";
|
||||
import LoggerExtension from "../collaboration/LoggerExtension";
|
||||
import MetricsExtension from "../collaboration/MetricsExtension";
|
||||
@@ -79,7 +80,7 @@ export default function init(
|
||||
socket.end(`HTTP/1.1 400 Bad Request\r\n`);
|
||||
});
|
||||
|
||||
server.on("shutdown", () => {
|
||||
return hocuspocus.destroy();
|
||||
});
|
||||
ShutdownHelper.add("collaboration", ShutdownOrder.normal, () =>
|
||||
hocuspocus.destroy()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import * as Tracing from "@server/logging/tracer";
|
||||
import { traceFunction } from "@server/logging/tracing";
|
||||
import { Document, Collection, View, User } from "@server/models";
|
||||
import { can } from "@server/policies";
|
||||
import ShutdownHelper, { ShutdownOrder } from "@server/utils/ShutdownHelper";
|
||||
import { getUserForJWT } from "@server/utils/jwt";
|
||||
import { websocketQueue } from "../queues";
|
||||
import WebsocketsProcessor from "../queues/processors/WebsocketsProcessor";
|
||||
@@ -72,7 +73,7 @@ export default function init(
|
||||
socket.end(`HTTP/1.1 400 Bad Request\r\n`);
|
||||
});
|
||||
|
||||
server.on("shutdown", () => {
|
||||
ShutdownHelper.add("websockets", ShutdownOrder.normal, async () => {
|
||||
Metrics.gaugePerInstance("websockets.count", 0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user