From f4efb13612bf4906248bbaf52600c25e670adc48 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Fri, 3 Apr 2026 11:41:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20restartGateway=20=E6=94=B9=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=EF=BC=8C=E4=BF=AE=E5=A4=8D=20inactive=20=E6=97=B6=20P?= =?UTF-8?q?IN=20=E4=B8=8D=E9=97=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原来 removeProviderByName 内用 execSync 调 pkill,在 showPin 前 阻塞事件循环约 100ms+;若 vfdservice 是 gateway 子进程则管道无 读端,导致 showPin 写入失败或 blink setTimeout 无法触发。 改为 exec(异步):pkill 在后台执行,不阻塞事件循环,LED/VFD 操作(showPin blink)可正常调度。 Made-with: Cursor --- lib/openclaw-provider.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/openclaw-provider.js b/lib/openclaw-provider.js index fe53669..a507560 100644 --- a/lib/openclaw-provider.js +++ b/lib/openclaw-provider.js @@ -4,7 +4,7 @@ const fs = require('fs'); const path = require('path'); const http = require('http'); const https = require('https'); -const { execSync } = require('child_process'); +const { exec } = require('child_process'); const log = require('./logger'); const { resolveOpenclawConfigFile } = require('./frpc'); @@ -17,14 +17,18 @@ let _busy = false; /** * 终止 openclaw-gateway 进程,由 systemd --user 自动重新拉起以读取新配置。 * 每次写盘 openclaw.json 成功后应调用一次。 + * 使用异步 exec,不阻塞 Node.js 事件循环,避免干扰 LED / VFD 等后续操作。 */ function restartGateway() { - try { - execSync('pkill -9 -x openclaw-gateway', { timeout: 3000 }); - log.info('openclaw-provider', 'openclaw-gateway 已终止,等待自动重启'); - } catch (_) { - log.info('openclaw-provider', 'openclaw-gateway 进程不存在,无需终止'); - } + exec('pkill -9 -x openclaw-gateway', (err) => { + if (err && err.code !== 1) { + log.warn('openclaw-provider', `restartGateway: ${err.message}`); + } else if (!err) { + log.info('openclaw-provider', 'openclaw-gateway 已终止,等待自动重启'); + } else { + log.info('openclaw-provider', 'openclaw-gateway 进程不存在,无需终止'); + } + }); } function authProfilesPathFromConfig(configFile) {