Skip to content

Commit e9e5e92

Browse files
authored
Refactor api-proxy SIGTERM/SIGINT shutdown flow into a shared handler (#3209)
* Initial plan * refactor: dedupe api-proxy graceful shutdown handlers * refactor: keep async signal handler wrappers --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent ff0e5ef commit e9e5e92

1 file changed

Lines changed: 5 additions & 16 deletions

File tree

containers/api-proxy/server.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ if (require.main === module) {
664664
});
665665
}
666666

667-
process.on('SIGTERM', async () => {
668-
logRequest('info', 'shutdown', { message: 'Received SIGTERM, shutting down gracefully' });
667+
async function shutdownGracefully(signal) {
668+
logRequest('info', 'shutdown', { message: `Received ${signal}, shutting down gracefully` });
669669
for (const adapter of registeredAdapters) {
670670
if (typeof adapter.getOidcProvider === 'function') {
671671
adapter.getOidcProvider()?.shutdown();
@@ -676,21 +676,10 @@ if (require.main === module) {
676676
}
677677
await closeLogStream();
678678
process.exit(0);
679-
});
679+
}
680680

681-
process.on('SIGINT', async () => {
682-
logRequest('info', 'shutdown', { message: 'Received SIGINT, shutting down gracefully' });
683-
for (const adapter of registeredAdapters) {
684-
if (typeof adapter.getOidcProvider === 'function') {
685-
adapter.getOidcProvider()?.shutdown();
686-
}
687-
if (typeof adapter.getAwsOidcProvider === 'function') {
688-
adapter.getAwsOidcProvider()?.shutdown();
689-
}
690-
}
691-
await closeLogStream();
692-
process.exit(0);
693-
});
681+
process.on('SIGTERM', async () => shutdownGracefully('SIGTERM'));
682+
process.on('SIGINT', async () => shutdownGracefully('SIGINT'));
694683
}
695684

696685
// ── Exports (for testing) ─────────────────────────────────────────────────────

0 commit comments

Comments
 (0)