fix(server-runtime): shutdown server on interruption properly (#1356)

Co-authored-by-agent: Claude Opus 4.6
This commit is contained in:
Rin
2026-03-14 21:44:13 +08:00
committed by GitHub
parent 9fc9955615
commit 1a1f720c93
2 changed files with 16 additions and 5 deletions
+14 -1
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env tsx
import { env } from 'node:process'
import { env, exit } from 'node:process'
import { createServer } from '../server'
@@ -8,4 +8,17 @@ const server = createServer({
port: env.PORT ? Number.parseInt(env.PORT) : 6121,
})
let stopping = false
async function shutdown() {
if (stopping)
return
stopping = true
await server.stop()
exit(0)
}
process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)
server.start()
+2 -4
View File
@@ -99,9 +99,7 @@ export function createServer(opts?: ServerOptions): Server {
return
}
if (!closeActiveConnections) {
log.withError(error).error('Error closing WebSocket server')
}
log.withError(error).error('Error closing WebSocket server')
}
finally {
serverInstance = null
@@ -175,7 +173,7 @@ export function createServer(opts?: ServerOptions): Server {
}
async function stop() {
await closeServer()
await closeServer(true)
}
async function restart() {