diff --git a/packages/server/src/connection.ts b/packages/server/src/connection.ts index b416676..1042d58 100644 --- a/packages/server/src/connection.ts +++ b/packages/server/src/connection.ts @@ -7,7 +7,7 @@ * - Connectivity check before registration */ -import { type DeviceConfig, type DeviceIdentity } from "@yuzu-gca/shared"; +import { type DeviceConfig } from "@yuzu-gca/shared"; export interface ConnectionState { status: "disconnected" | "connecting" | "connected" | "reconnecting"; diff --git a/packages/server/src/main.ts b/packages/server/src/main.ts index 26109fd..f24e511 100644 --- a/packages/server/src/main.ts +++ b/packages/server/src/main.ts @@ -58,18 +58,20 @@ console.log(` Gateway: ${config.gateway.url}`); console.log(` Tools: ${toolHandlers.size} implemented`); console.log(` Port: ${port}`); -bootstrap(opts, port).then(() => { +bootstrap(opts, port).then(async () => { console.log(`[Yuzu-GCA] Ready.`); // Start Gateway connection lifecycle const connMgr = new ConnectionManager(config, (state) => { console.log(`[Gateway] ${state.status} (attempt ${state.reconnectAttempt})`); }); - connMgr.start(); - // Graceful shutdown - process.on("SIGINT", () => { connMgr.stop(); process.exit(0); }); - process.on("SIGTERM", () => { connMgr.stop(); process.exit(0); }); + // Register signal handlers BEFORE connection start + const shutdown = async () => { connMgr.stop(); setTimeout(() => process.exit(0), 300); }; + process.on("SIGINT", shutdown); + process.on("SIGTERM", shutdown); + + await connMgr.start(); }).catch(err => { console.error(`[Yuzu-GCA] Fatal:`, err); process.exit(1); diff --git a/packages/server/tsconfig.json b/packages/server/tsconfig.json index 499a856..d34bad9 100644 --- a/packages/server/tsconfig.json +++ b/packages/server/tsconfig.json @@ -1 +1 @@ -{"compilerOptions":{"target":"ES2022","module":"Node16","outDir":"dist","rootDir":"src","declaration":true,"strict":true,"esModuleInterop":true,"skipLibCheck":true},"include":["src"]} +{"compilerOptions":{"target":"ES2022","module":"Node16","outDir":"dist","rootDir":"src","declaration":true,"strict":true,"esModuleInterop":true,"skipLibCheck":true},"include":["src"]}