@myassis/gateway 1.0.46 → 1.0.47

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.
@@ -521,20 +521,40 @@ async function updateService() {
521
521
  `if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }`,
522
522
  `function Write-UpdateLog { param([string]$Message) Add-Content -Path $logPath -Encoding UTF8 -Value \"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $Message\" }`,
523
523
  `function Stop-GatewayProcess {`,
524
- ` if (-not (Test-Path $pidFile)) { Write-UpdateLog 'pid file not found, skip stop'; return }`,
524
+ ` $stoppedPids = @{}`,
525
+ ` if (Test-Path $pidFile) {`,
526
+ ` try {`,
527
+ ` $pidValue = (Get-Content $pidFile -Raw).Trim()`,
528
+ ` if ($pidValue) {`,
529
+ ` $pidInt = [int]$pidValue`,
530
+ ` Write-UpdateLog \"stopping gateway process by pid file pid=$pidInt\"`,
531
+ ` try { Stop-Process -Id $pidInt -Force -ErrorAction Stop; $stoppedPids[$pidInt] = $true } catch { Write-UpdateLog \"stop-process by pid failed: $($_.Exception.Message)\" }`,
532
+ ` }`,
533
+ ` } catch { Write-UpdateLog \"read pid file error: $($_.Exception.Message)\" }`,
534
+ ` Remove-Item $pidFile -Force -ErrorAction SilentlyContinue`,
535
+ ` } else { Write-UpdateLog 'pid file not found, fallback to path match' }`,
525
536
  ` try {`,
526
- ` $pidValue = (Get-Content $pidFile -Raw).Trim()`,
527
- ` if (-not $pidValue) { return }`,
528
- ` $pidInt = [int]$pidValue`,
529
- ` Write-UpdateLog \"stopping gateway process pid=$pidInt\"`,
530
- ` try { Stop-Process -Id $pidInt -Force -ErrorAction Stop } catch { Write-UpdateLog \"stop-process failed: $($_.Exception.Message)\" }`,
537
+ ` $targetFull = [System.IO.Path]::GetFullPath($currentExe)`,
538
+ ` $targetName = [System.IO.Path]::GetFileNameWithoutExtension($currentExe)`,
539
+ ` $procs = Get-Process -Name $targetName -ErrorAction SilentlyContinue`,
540
+ ` foreach ($proc in $procs) {`,
541
+ ` try {`,
542
+ ` $procPath = $null`,
543
+ ` try { $procPath = $proc.Path } catch { $procPath = $null }`,
544
+ ` if ($procPath -and ([System.IO.Path]::GetFullPath($procPath) -ieq $targetFull)) {`,
545
+ ` Write-UpdateLog \"stopping gateway process by path pid=$($proc.Id), path=$procPath\"`,
546
+ ` try { Stop-Process -Id $proc.Id -Force -ErrorAction Stop; $stoppedPids[$proc.Id] = $true } catch { Write-UpdateLog \"stop-process by path failed pid=$($proc.Id): $($_.Exception.Message)\" }`,
547
+ ` }`,
548
+ ` } catch { Write-UpdateLog \"inspect process failed pid=$($proc.Id): $($_.Exception.Message)\" }`,
549
+ ` }`,
550
+ ` } catch { Write-UpdateLog \"enumerate processes error: $($_.Exception.Message)\" }`,
551
+ ` foreach ($spid in $stoppedPids.Keys) {`,
531
552
  ` for ($w = 0; $w -lt 30; $w++) {`,
532
- ` $p = Get-Process -Id $pidInt -ErrorAction SilentlyContinue`,
553
+ ` $p = Get-Process -Id $spid -ErrorAction SilentlyContinue`,
533
554
  ` if (-not $p) { break }`,
534
555
  ` Start-Sleep -Milliseconds 500`,
535
556
  ` }`,
536
- ` Remove-Item $pidFile -Force -ErrorAction SilentlyContinue`,
537
- ` } catch { Write-UpdateLog \"stop gateway error: $($_.Exception.Message)\" }`,
557
+ ` }`,
538
558
  `}`,
539
559
  `function Start-GatewayProcess {`,
540
560
  ` if (-not (Test-Path $launcher)) { Write-UpdateLog \"launcher script not found: $launcher\"; return }`,
@@ -548,17 +568,35 @@ async function updateService() {
548
568
  ` Start-Sleep -Seconds 1`,
549
569
  ` Write-UpdateLog 'waiting executable unlock'`,
550
570
  ` $moved = $false`,
551
- ` for ($i = 0; $i -lt 60; $i++) {`,
571
+ ` $lastMoveError = ''`,
572
+ ` for ($i = 0; $i -lt 120; $i++) {`,
552
573
  ` try {`,
553
574
  ` if (Test-Path $backupExe) { Remove-Item $backupExe -Force -ErrorAction SilentlyContinue }`,
554
- ` Move-Item $currentExe $backupExe -Force`,
575
+ ` Move-Item $currentExe $backupExe -Force -ErrorAction Stop`,
555
576
  ` $moved = $true`,
556
577
  ` break`,
557
578
  ` } catch {`,
579
+ ` $lastMoveError = $_.Exception.Message`,
580
+ ` if (($i % 5) -eq 0) { Write-UpdateLog \"move-item failed try=$i error=$lastMoveError\" }`,
581
+ ` if (($i -gt 0) -and (($i % 10) -eq 0)) { try { Stop-GatewayProcess } catch { Write-UpdateLog \"retry stop failed: $($_.Exception.Message)\" } }`,
558
582
  ` Start-Sleep -Seconds 1`,
559
583
  ` }`,
560
584
  ` }`,
561
- ` if (-not $moved) { throw '等待旧版本可执行文件解锁超时' }`,
585
+ ` if (-not $moved) {`,
586
+ ` $holders = ''`,
587
+ ` try {`,
588
+ ` $targetName = [System.IO.Path]::GetFileNameWithoutExtension($currentExe)`,
589
+ ` $procs = Get-Process -Name $targetName -ErrorAction SilentlyContinue`,
590
+ ` $infos = @()`,
591
+ ` foreach ($proc in $procs) {`,
592
+ ` try { $procPath = $proc.Path } catch { $procPath = '' }`,
593
+ ` $infos += \"pid=$($proc.Id) path=$procPath\"`,
594
+ ` }`,
595
+ ` $holders = ($infos -join '; ')`,
596
+ ` } catch { $holders = \"enumerate failed: $($_.Exception.Message)\" }`,
597
+ ` Write-UpdateLog \"executable still locked, lastError=$lastMoveError, holders=$holders\"`,
598
+ ` throw \"等待旧版本可执行文件解锁超时: lastError=$lastMoveError; holders=$holders\"`,
599
+ ` }`,
562
600
  ` Write-UpdateLog 'moving new executable'`,
563
601
  ` Move-Item $tmpExe $currentExe -Force`,
564
602
  ` Start-Sleep -Seconds 1`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.46",
3
+ "version": "1.0.47",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "bin": {