From ad0984bf64c5bb3228d2e881c7f9135a0ac97904 Mon Sep 17 00:00:00 2001 From: chaos-zhu Date: Sat, 17 Aug 2024 18:02:57 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=B8=8B=E5=8F=91=E6=89=A7=E8=A1=8C=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E9=80=9A=E7=9F=A5=E9=87=8D=E5=A4=8D=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/socket/onekey.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/app/socket/onekey.js b/server/app/socket/onekey.js index 5d70dba..514c7a9 100644 --- a/server/app/socket/onekey.js +++ b/server/app/socket/onekey.js @@ -103,8 +103,7 @@ module.exports = (httpServer) => { return } setTimeout(() => { - // 超时未执行完成,断开连接 - disconnectAllExecClient() + // 超时未执行完成,强制断开连接 const { connecting, executing } = execStatusEnum execResult.forEach(item => { // 连接中和执行中的状态设定为超时 @@ -116,6 +115,7 @@ module.exports = (httpServer) => { asyncSendNotice('onekey_complete', '批量指令执行超时', reason) socket.emit('timeout', { reason, result: execResult }) socket.disconnect() + disconnectAllExecClient() }, timeout * 1000) console.log('hosts:', hosts) // console.log('token:', token) @@ -128,7 +128,8 @@ module.exports = (httpServer) => { socket.emit('ready') let execPromise = targetHostsInfo.map((hostInfo, index) => { // eslint-disable-next-line no-async-promise-executor - return new Promise(async (resolve) => { + return new Promise(async (resolve, reject) => { + setTimeout(() => reject('执行超时'), timeout * 1000) let { authType, host, port, username } = hostInfo let authInfo = { host, port, username } let curRes = { command, host, name: hostInfo.name, result: '', status: execStatusEnum.connecting, date: Date.now() - (targetHostsInfo.length - index) } // , execStatusEnum @@ -174,11 +175,15 @@ module.exports = (httpServer) => { } }) }) - await Promise.all(execPromise) - consola.success('onekey执行完成') - socket.emit('exec_complete') - asyncSendNotice('onekey_complete', '批量指令执行完成', '请登录面板查看执行结果') - socket.disconnect() + try { + await Promise.all(execPromise) + consola.success('onekey执行完成') + socket.emit('exec_complete') + asyncSendNotice('onekey_complete', '批量指令执行完成', '请登录面板查看执行结果') + socket.disconnect() + } catch (error) { + consola.error('onekey执行失败', error) + } }) socket.on('disconnect', async (reason) => {