Skip to content

Commit dd59c8c

Browse files
committed
Use a specific error code (99) for inactivity shutdowns
Shouldn't matter much, but this might enable us to debug this better if it starts happening spuriously in future.
1 parent 12cd930 commit dd59c8c

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/api/api-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class HttpToolkitServerApi extends events.EventEmitter {
122122
httpClient,
123123
{
124124
onTriggerUpdate: () => this.emit('update-requested'),
125-
onTriggerShutdown: () => shutdown('API call')
125+
onTriggerShutdown: () => shutdown(0, 'API call')
126126
}
127127
)
128128

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ function manageBackgroundServices(
138138
}
139139

140140
shutdownTimer = setTimeout(() => {
141-
if (activeSessions === 0) shutdown('10 minutes inactive');
141+
if (activeSessions === 0) {
142+
shutdown(99, '10 minutes inactive');
143+
}
142144
}, 1000 * 60 * 10).unref();
143145
}
144146
});

src/shutdown.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ type ShutdownHandler = () => Promise<unknown>;
55
const shutdownHandlers: Array<ShutdownHandler> = [];
66

77
export function registerShutdownHandler() {
8-
process.on('SIGTERM', () => shutdown('SIGTERM'));
9-
process.on('SIGINT', () => shutdown('SIGINT'));
8+
process.on('SIGTERM', () => shutdown(0, 'SIGTERM'));
9+
process.on('SIGINT', () => shutdown(0, 'SIGINT'));
1010
}
1111

1212
export function addShutdownHandler(handler: ShutdownHandler) {
1313
shutdownHandlers.push(handler);
1414
}
1515

16-
export async function shutdown(cause: string) {
16+
export async function shutdown(code: number, cause: string) {
1717
console.log(`Shutting down after ${cause}...`);
1818

1919
const shutdownPromises = Promise.all(shutdownHandlers.map(
@@ -31,6 +31,6 @@ export async function shutdown(cause: string) {
3131
delay(2000) // After 2 seconds, we just close anyway, we're done.
3232
]);
3333

34-
process.exit(0);
34+
process.exit(code);
3535
}
3636

0 commit comments

Comments
 (0)