@myassis/gateway 1.0.49 → 1.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -158,20 +158,19 @@ function writeGatewayLauncherScript(exePath, scriptPath, workDir) {
|
|
|
158
158
|
"$workDir = '" + workDir.replace(/\\/g, '\\\\') + "'",
|
|
159
159
|
"$pidFile = '" + GATEWAY_PID_FILE.replace(/\\/g, '\\\\') + "'",
|
|
160
160
|
"",
|
|
161
|
-
"# 启动 Gateway
|
|
161
|
+
"# 启动 Gateway(无参启动,直接进入 HTTP Server 模式,监听默认端口 3001)",
|
|
162
162
|
"$psi = New-Object System.Diagnostics.ProcessStartInfo",
|
|
163
163
|
"$psi.FileName = $exe",
|
|
164
164
|
"$psi.WorkingDirectory = $workDir",
|
|
165
165
|
"$psi.UseShellExecute = $false",
|
|
166
|
-
"$psi.RedirectStandardOutput = $true",
|
|
167
|
-
"$psi.RedirectStandardError = $true",
|
|
168
166
|
"$psi.CreateNoWindow = $true",
|
|
167
|
+
"# 注意:不重定向 stdout/stderr,避免匿名管道 4KB 缓冲区打满后阻塞 gateway 的事件循环",
|
|
169
168
|
"$psi.Environment['NODE_ENV'] = 'production'",
|
|
170
169
|
"$proc = [System.Diagnostics.Process]::Start($psi)",
|
|
171
170
|
"if ($proc) {",
|
|
172
171
|
" $proc.Id.ToString() | Out-File -FilePath $pidFile -Encoding UTF8",
|
|
173
|
-
" $proc.WaitForExit()",
|
|
174
172
|
"}",
|
|
173
|
+
"# fire-and-forget:不 WaitForExit,PowerShell 立即退出,省 ~30MB 常驻内存",
|
|
175
174
|
].join('\r\n');
|
|
176
175
|
// 确保目标目录存在(%LOCALAPPDATA%\我的助手 首次启动时可能不存在)
|
|
177
176
|
try {
|
|
@@ -437,11 +436,22 @@ async function ensureAutoStartHealthy() {
|
|
|
437
436
|
// 2) 未注册→开发机或从未安装,不做任何事
|
|
438
437
|
if (!currentValue)
|
|
439
438
|
return;
|
|
440
|
-
// 3)
|
|
439
|
+
// 3) 评估健康度(Run key + 脚本内容双重检查)
|
|
441
440
|
const lower = currentValue.toLowerCase();
|
|
442
441
|
const hasPowershell = lower.includes('powershell.exe');
|
|
443
442
|
const pointsToNewPath = lower.includes(GATEWAY_LAUNCHER_FILE.toLowerCase());
|
|
444
|
-
|
|
443
|
+
// 脚本内容健康:不能含 RedirectStandardOutput(旧版本会因管道阻塞卡死)
|
|
444
|
+
let scriptHealthy = false;
|
|
445
|
+
try {
|
|
446
|
+
if (fs_1.default.existsSync(GATEWAY_LAUNCHER_FILE)) {
|
|
447
|
+
const scriptContent = fs_1.default.readFileSync(GATEWAY_LAUNCHER_FILE, 'utf8');
|
|
448
|
+
// 老版含 RedirectStandardOutput(管道阻塞 bug)或 WaitForExit(陪跑浪费内存)→ 判定不健康
|
|
449
|
+
scriptHealthy = !scriptContent.includes('RedirectStandardOutput')
|
|
450
|
+
&& !scriptContent.includes('WaitForExit');
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
catch { /* ignore */ }
|
|
454
|
+
if (hasPowershell && pointsToNewPath && scriptHealthy)
|
|
445
455
|
return; // 已健康
|
|
446
456
|
logger.warn(`检测到 Run key 不健康,自动修复。current='${currentValue}'`);
|
|
447
457
|
// 4) 重写 launcher 脚本到新路径
|