Skip to content

Commit 6356f8a

Browse files
author
Taois
committed
fix: 守护进程退出问题
1 parent 4966a86 commit 6356f8a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ fastify.addHook('onReady', async () => {
4747
}
4848
});
4949

50-
// 停止时清理守护进程
51-
fastify.addHook('onClose', async () => {
50+
async function onClose() {
5251
try {
5352
await daemon.stopDaemon();
5453
fastify.log.info('Python守护进程已停止');
5554
} catch (error) {
5655
fastify.log.error(`停止Python守护进程失败: ${error.message}`);
5756
}
57+
}
58+
59+
// 停止时清理守护进程
60+
fastify.addHook('onClose', async () => {
61+
await onClose();
5862
});
5963

6064
// 给静态目录插件中心挂载basic验证
@@ -100,7 +104,7 @@ const handleExit = async (signal) => {
100104
try {
101105
console.log(`\nReceived ${signal}, closing server...`);
102106
// Fastify 提供的关闭方法,内部会触发 onClose 钩子
103-
await stop();
107+
await onClose();
104108
console.log('Fastify closed successfully');
105109
process.exit(0);
106110
} catch (err) {

0 commit comments

Comments
 (0)