From 93ca593f1bbc8b47944425d6454e5eeff361b5f5 Mon Sep 17 00:00:00 2001 From: LukeMackin Date: Wed, 22 Jul 2026 17:33:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=A1=E6=9F=A5=E9=98=BB=E6=96=AD=20?= =?UTF-8?q?=E2=80=94=20BOM+=E4=BF=A1=E5=8F=B7=E6=97=B6=E5=BA=8F+unused=20i?= =?UTF-8?q?mport+exit=E5=89=8D=E7=AD=89=E5=BE=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/connection.ts | 2 +- packages/server/src/main.ts | 12 +++++++----- packages/server/tsconfig.json | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) 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"]}