mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-23 22:15:49 +00:00
fix: handle instance shutdown more gracefully
This commit is contained in:
parent
da25534256
commit
40006f992c
@ -178,8 +178,16 @@ export const instanceService = mkSingleton(
|
|||||||
const childProcess = await pbService.spawn(spawnArgs)
|
const childProcess = await pbService.spawn(spawnArgs)
|
||||||
|
|
||||||
const { exitCode, stopped, started, url: internalUrl } = childProcess
|
const { exitCode, stopped, started, url: internalUrl } = childProcess
|
||||||
|
exitCode.then((code) => {
|
||||||
|
dbg(`Instance exited with code ${code}`)
|
||||||
|
api?.shutdown()
|
||||||
|
})
|
||||||
|
|
||||||
shutdownManager.push(() => {
|
shutdownManager.push(() => {
|
||||||
|
if (stopped()) {
|
||||||
|
dbg(`Instance already stopped`)
|
||||||
|
return
|
||||||
|
}
|
||||||
dbg(`killing ${id}`)
|
dbg(`killing ${id}`)
|
||||||
childProcess.kill().catch((err) => {
|
childProcess.kill().catch((err) => {
|
||||||
error(`Error killing ${id}`, { err })
|
error(`Error killing ${id}`, { err })
|
||||||
@ -207,7 +215,7 @@ export const instanceService = mkSingleton(
|
|||||||
userInstanceLogger.info(
|
userInstanceLogger.info(
|
||||||
`Instance has been idle for ${DAEMON_PB_IDLE_TTL()}ms. Hibernating to conserve resources.`,
|
`Instance has been idle for ${DAEMON_PB_IDLE_TTL()}ms. Hibernating to conserve resources.`,
|
||||||
)
|
)
|
||||||
shutdownManager.forEach((fn) => fn())
|
api.shutdown()
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
dbg(`${openRequestCount} requests remain open`)
|
dbg(`${openRequestCount} requests remain open`)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user