Skip to content
Closed
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
16 changes: 11 additions & 5 deletions packages/core/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ export class Application extends Context implements LifeCycleObserver {
this.bind(CoreBindings.APPLICATION_CONFIG).to(this.options);

const shutdownConfig = this.options.shutdown ?? {};
this.setupShutdown(
shutdownConfig.signals ?? ['SIGTERM'],
shutdownConfig.gracePeriod,
);
this.setupShutdown(shutdownConfig);
}

/**
Expand Down Expand Up @@ -424,7 +421,16 @@ export class Application extends Context implements LifeCycleObserver {
* @param signals - An array of signals to be trapped
* @param gracePeriod - A grace period in ms before forced exit
*/
protected setupShutdown(signals: NodeJS.Signals[], gracePeriod?: number) {
protected setupShutdown({
signals = ['SIGTERM'],
gracePeriod,
}: ShutdownOptions) {
// Increase the max listeners of process to be 256
// Mocha parallel testing reports more than 11 listeners are added
const numOfListeners = process.getMaxListeners();
if (numOfListeners < 256) {
process.setMaxListeners(256);
}
const cleanup = async (signal: string) => {
const kill = () => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
Expand Down