feat(server): add graceful shutdown handling
Some checks failed
Auto Changelog & Release / detect-version-change (push) Successful in 4s
Auto Changelog & Release / changelog-only (push) Successful in 8s
Auto Changelog & Release / release (push) Has been skipped
Build and upload Docker nightly image / build-and-push (push) Has been cancelled
Some checks failed
Auto Changelog & Release / detect-version-change (push) Successful in 4s
Auto Changelog & Release / changelog-only (push) Successful in 8s
Auto Changelog & Release / release (push) Has been skipped
Build and upload Docker nightly image / build-and-push (push) Has been cancelled
- Introduce signal listeners for SIGINT and SIGTERM to handle shutdown - Use AbortController to terminate the server gracefully - Improve server reliability and resource cleanup during termination
This commit is contained in:
11
src/main.ts
11
src/main.ts
@@ -3,6 +3,7 @@ import { Env } from './env.ts';
|
||||
import { ltProxyAuth } from './ltProxyAuth.ts';
|
||||
import { ltProxyHandler } from './ltProxyHandler.ts';
|
||||
|
||||
const ac = new AbortController();
|
||||
const httpKernel = new HttpKernel();
|
||||
|
||||
httpKernel.route({
|
||||
@@ -11,9 +12,19 @@ httpKernel.route({
|
||||
}).middleware(ltProxyAuth).handle(ltProxyHandler);
|
||||
|
||||
Deno.serve({
|
||||
signal: ac.signal,
|
||||
port: Env.proxyPort,
|
||||
hostname: Env.proxyHost,
|
||||
onListen: ({ hostname, port }) => {
|
||||
console.info(`lt-auth-proxy listening on ${hostname}:${port}`);
|
||||
},
|
||||
}, async (req) => await httpKernel.handle(req));
|
||||
|
||||
const shutdown = () => {
|
||||
console.info('Shutting down the server...');
|
||||
ac.abort();
|
||||
console.info('Server shut down successfully.');
|
||||
};
|
||||
|
||||
Deno.addSignalListener('SIGINT', shutdown);
|
||||
Deno.addSignalListener('SIGTERM', shutdown);
|
||||
|
Reference in New Issue
Block a user