解决了按需启动因为socket关闭回调无法触发可能导致假死无法唤醒的问题

This commit is contained in:
zhangyuheng 2023-12-13 17:14:21 +08:00
parent 672c7fc340
commit e173e8abcd
3 changed files with 8 additions and 7 deletions

View File

@ -67,14 +67,13 @@ export class OnDemandRunner {
// create socket server
this.socketServer = this.startSocketServer(port);
// waiting for player connect then close socket server
await new Promise<void>((ok, reject) => {
this.socketServer.on('close', () => {
ok();
while (this.socketServer.listening) {
await new Promise<void>((ok) => {
setTimeout(ok, 2000);
});
this.socketServer.on('error', (error: any) => {
reject(error);
});
});
}
logger.info(`${this.instance.instanceUuid} `, $t("on_demand.playerConnected"));
this.instance.println("INFO", $t("on_demand.playerConnected"));
this.socketServer = null;
}
resolve();

View File

@ -228,6 +228,7 @@
"cantStartOnDemand": "May not a Minecraft server, unable to start on demand.",
"over30minClose": "Instance has been vancant for more than 30 minutes, going to sleep...",
"instanceSleeping": "Instance is sleeping, waiting for player to wake it up.",
"playerConnected": "Connection recived, waking up instance...",
"start": "On demand sequence started.",
"stop": "On demand sequence stopped."
}

View File

@ -228,6 +228,7 @@
"cantStartOnDemand": "可能由于不是Minecraft服务器无法使用按需启动功能。",
"over30minClose": "实例超过30分钟不活跃正在进入休眠状态。",
"instanceSleeping": "实例已休眠,等待玩家唤醒。",
"playerConnected": "检测到连接请求,正在唤醒实例。",
"start": "已进入按需启动模式实例将在超过30分钟不活跃后自动关闭并在玩家进入时自动开启。",
"stop": "已退出按需启动模式。"
}