fix(server): let the CLI server exit on Ctrl+C and SIGTERM (UF-041)
The OAuth routes started a module-level cleanup interval that was never cleared or unref'd. The service's SIGTERM/SIGINT handler closes the server and relies on the event loop going empty, so the process kept running: a first Ctrl+C in `npx waggle` or `npm run dev:server` left it alive, and SIGTERM never ended it. The interval is now unref'd. The launcher tests left two `waggle` processes behind on every run: they stopped `npx` but not the waggle process it started. They now start it in its own process group and stop the whole group, with a SIGKILL fallback, and a new test checks that the built CLI exits by itself after SIGTERM.
This commit is contained in:
@@ -63,13 +63,14 @@ const OAUTH_PROVIDERS: Record<string, OAuthProviderConfig> = {
|
||||
/** In-memory store for OAuth state parameters (CSRF protection) */
|
||||
const pendingStates = new Map<string, { provider: string; createdAt: number }>();
|
||||
|
||||
// Clean up expired states every 10 minutes
|
||||
// Clean up expired states every 10 minutes. Unref'd so this housekeeping timer
|
||||
// never keeps the process alive after the server closes on SIGTERM/SIGINT.
|
||||
setInterval(() => {
|
||||
const cutoff = Date.now() - 10 * 60 * 1000;
|
||||
for (const [key, val] of pendingStates) {
|
||||
if (val.createdAt < cutoff) pendingStates.delete(key);
|
||||
}
|
||||
}, 10 * 60 * 1000);
|
||||
}, 10 * 60 * 1000).unref();
|
||||
|
||||
// ── Routes ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user