Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmd-api-server): shutdown hook was not waiting for promises #3365

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Server as SecureServer } from "https";
import type { Request, Response, RequestHandler } from "express";
import type { ServerOptions as SocketIoServerOptions } from "socket.io";
import type { Socket as SocketIoSocket } from "socket.io";
import exitHook from "async-exit-hook";
import exitHook, { IAsyncExitHookDoneCallback } from "async-exit-hook";
import os from "os";
import path from "path";
import tls from "tls";
Expand Down Expand Up @@ -208,6 +208,23 @@ export class ApiServer {
level: options.config.logLevel,
});

if (this.enableShutdownHook) {
exitHook((onHookDone: IAsyncExitHookDoneCallback) => {
this.log.info("Starting async-exit-hook for cmd-api-server ...");
this.shutdown()
.catch((ex: unknown) => {
this.log.warn("Failed async-exit-hook for cmd-api-server", ex);
throw ex;
})
.finally(() => {
this.log.info("Concluded async-exit-hook for cmd-api-server ...");
onHookDone();
});
this.log.info("Started async-exit-hook for cmd-api-server OK");
});
this.log.info("Registered async-exit-hook for cmd-api-server shutdown.");
}

const defaultPluginsPath = path.join(
os.tmpdir(),
"org",
Expand Down
Loading