From 8f0a4fe71b4c49aae56d9dd5614f14a0bed32435 Mon Sep 17 00:00:00 2001 From: Marcelo Ochoa Date: Thu, 13 Mar 2025 17:46:32 +0000 Subject: [PATCH] refactor: remove inactivity timer and enhance server shutdown handling --- src/oracle/index.ts | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/oracle/index.ts b/src/oracle/index.ts index 030ddc5..95dd6e8 100644 --- a/src/oracle/index.ts +++ b/src/oracle/index.ts @@ -246,41 +246,22 @@ const PromptsListRequestSchema = z.object({ params: z.object({}), }); -let inactivityTimer: NodeJS.Timeout | null = null; -const INACTIVITY_TIMEOUT = 60000; // 1 minute - -function resetInactivityTimer() { - if (inactivityTimer) { - clearTimeout(inactivityTimer); - } - inactivityTimer = setTimeout(() => { - // console.log("No activity detected for 30 seconds. Shutting down server..."); - process.exit(0); - }, INACTIVITY_TIMEOUT); -} - server.setRequestHandler(PromptsListRequestSchema, async () => { - resetInactivityTimer(); return { prompts, }; }); -process.on("SIGINT", async () => { - console.log("Received SIGINT. Shutting down server..."); - process.exit(0); -}); - -process.on("SIGTERM", async () => { - console.log("Received SIGTERM. Shutting down server..."); - process.exit(0); -}); - async function runServer() { await initializePool(connectionString); // Initialize the pool before starting the server const transport = new StdioServerTransport(); await server.connect(transport); - resetInactivityTimer(); // Start the inactivity timer when the server starts } runServer().catch(console.error); + +process.stdin.on("close", () => { + console.error("Oracle MCP Server closed"); + server.close(); + process.exit(0); +});