@myassis/gateway 1.0.68 → 1.0.69
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.
- package/dist/services/ServiceManager.js +27 -23
- package/package.json +1 -1
|
@@ -199,18 +199,18 @@ function writeGatewayLauncherScript(exePath, scriptPath, workDir) {
|
|
|
199
199
|
'',
|
|
200
200
|
'function Start-Gateway {',
|
|
201
201
|
" Write-Log '启动 Gateway 进程...'",
|
|
202
|
-
'
|
|
203
|
-
'
|
|
204
|
-
'
|
|
205
|
-
'
|
|
206
|
-
'
|
|
207
|
-
'
|
|
208
|
-
'
|
|
209
|
-
|
|
210
|
-
'
|
|
211
|
-
'
|
|
212
|
-
|
|
213
|
-
|
|
202
|
+
' # 用 Start-Process 启动,不重定向 stdout/stderr,避免:',
|
|
203
|
+
' # 1) 管道缓冲区填满后 gateway 卡死(4KB 缓冲区无人读取)',
|
|
204
|
+
' # 2) 父 PS 句柄继承导致 gateway 写 stdout 崩溃',
|
|
205
|
+
' try {',
|
|
206
|
+
' $proc = Start-Process -FilePath $exe -WorkingDirectory $workDir -WindowStyle Hidden -PassThru -ErrorAction Stop',
|
|
207
|
+
' if ($proc -and $proc.Id) {',
|
|
208
|
+
' $proc.Id.ToString() | Out-File -FilePath $pidFile -Encoding UTF8',
|
|
209
|
+
" Write-Log \"Gateway 已启动,PID=$($proc.Id)\"",
|
|
210
|
+
' return $proc',
|
|
211
|
+
' }',
|
|
212
|
+
' } catch {',
|
|
213
|
+
" Write-Log \"Gateway 启动失败: $($_.Exception.Message)\"",
|
|
214
214
|
' }',
|
|
215
215
|
" Write-Log 'Gateway 启动失败'",
|
|
216
216
|
' return $null',
|
|
@@ -226,10 +226,13 @@ function writeGatewayLauncherScript(exePath, scriptPath, workDir) {
|
|
|
226
226
|
'# 守护循环:监控进程状态,异常退出则自动重启',
|
|
227
227
|
'while ($true) {',
|
|
228
228
|
' try {',
|
|
229
|
-
' #
|
|
230
|
-
'
|
|
231
|
-
'
|
|
232
|
-
'
|
|
229
|
+
' # 每 5 秒检查一次进程是否仍在运行',
|
|
230
|
+
' Start-Sleep -Seconds 5',
|
|
231
|
+
'',
|
|
232
|
+
' # 进程已退出',
|
|
233
|
+
' if ($proc.HasExited) {',
|
|
234
|
+
' $exitCode = -1',
|
|
235
|
+
' try { $exitCode = $proc.ExitCode } catch { }',
|
|
233
236
|
" Write-Log \"Gateway 进程已退出,退出码=$exitCode\"",
|
|
234
237
|
'',
|
|
235
238
|
' # 检查是否是主动停止',
|
|
@@ -564,19 +567,20 @@ async function ensureAutoStartHealthy() {
|
|
|
564
567
|
const lower = currentValue.toLowerCase();
|
|
565
568
|
const hasPowershell = lower.includes('powershell.exe');
|
|
566
569
|
const pointsToNewPath = lower.includes(GATEWAY_LAUNCHER_FILE.toLowerCase());
|
|
567
|
-
// 脚本内容健康:不能含 RedirectStandardOutput
|
|
568
|
-
// 也不能是 UseShellExecute=$false(会继承父 PS 句柄,PS 退出后 gateway 写 stdout
|
|
570
|
+
// 脚本内容健康:不能含 RedirectStandardOutput(旧版管道阻塞 bug),
|
|
571
|
+
// 也不能是 UseShellExecute=$false(会继承父 PS 句柄,PS 退出后 gateway 写 stdout 崩溃),
|
|
572
|
+
// 并且必须含 Start-Process(新版守护脚本的启动方式)
|
|
569
573
|
let scriptHealthy = false;
|
|
570
574
|
try {
|
|
571
575
|
if (fs_1.default.existsSync(GATEWAY_LAUNCHER_FILE)) {
|
|
572
576
|
const scriptContent = fs_1.default.readFileSync(GATEWAY_LAUNCHER_FILE, 'utf8');
|
|
573
577
|
// 老版包含以下任一特征就重写:
|
|
574
|
-
// 1) RedirectStandardOutput → 管道阻塞旧 bug
|
|
575
|
-
// 2)
|
|
576
|
-
//
|
|
578
|
+
// 1) RedirectStandardOutput → 管道阻塞旧 bug(无人读管道导致 gateway 卡死)
|
|
579
|
+
// 2) UseShellExecute = $false → 句柄继承导致进程崩溃
|
|
580
|
+
// 新版必须用 Start-Process 启动(不含则说明是旧脚本)
|
|
577
581
|
scriptHealthy = !scriptContent.includes('RedirectStandardOutput')
|
|
578
|
-
&& !scriptContent.includes('
|
|
579
|
-
&&
|
|
582
|
+
&& !scriptContent.includes('UseShellExecute = $false')
|
|
583
|
+
&& scriptContent.includes('Start-Process');
|
|
580
584
|
}
|
|
581
585
|
}
|
|
582
586
|
catch { /* ignore */ }
|