fix(server-runtime): shutdown server on interruption properly (#1356)
Co-authored-by-agent: Claude Opus 4.6
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user