diff --git a/proto-cuda/windows-miner/start-mining.ps1 b/proto-cuda/windows-miner/start-mining.ps1 index 2243d70a8..2028f84d5 100644 --- a/proto-cuda/windows-miner/start-mining.ps1 +++ b/proto-cuda/windows-miner/start-mining.ps1 @@ -68,6 +68,22 @@ $script:tick = 0 # frame counter, drives the heartbeat marker $script:events = New-Object System.Collections.ArrayList $script:uploadOk = $true +function Get-ExitCode($inst) { + $code = $null + try { $code = $inst.proc.ExitCode } catch { } + if ($null -eq $code -and $inst.log -and (Test-Path $inst.log)) { + try { + $fs = New-Object IO.FileStream($inst.log, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite) + $len = $fs.Length; $n = [Math]::Min($len, 4096); $fs.Seek(-$n, [IO.SeekOrigin]::End) | Out-Null + $b = New-Object byte[] $n; [void]$fs.Read($b, 0, $n); $fs.Close() + $tail = [Text.Encoding]::UTF8.GetString($b) + if ($tail -match 'exiting with code (\d+)') { $code = [int]$Matches[1] } + elseif ($tail -match 'SEED CHANGE') { $code = 42 } + } catch { } + } + return $code +} + function Log([string]$msg) { $line = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $msg" if (-not $script:dashOn) { Write-Host $line } @@ -316,6 +332,7 @@ function Start-Miner($v, $inst) { } Set-Content -Path $inst.log -Value "igneum-mine-test $($inst.label) $machine $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') node $nodeUrl run $($inst.runId) start $($inst.starts)" $inst.proc = Start-Process -FilePath $miner -ArgumentList $margs -WorkingDirectory $(if ($v.name -eq 'amd') { Join-Path $root 'proto-opencl' } else { $root }) -RedirectStandardOutput $inst.log -RedirectStandardError $inst.err -NoNewWindow -PassThru + if ($inst.proc) { $null = $inst.proc.Handle } # without touching Handle, ExitCode comes back empty after the process ends $inst.startedAt = Get-Date Log "$($inst.label) started (pid $($inst.proc.Id)): `"$miner`" $($margs -join ' ') -> $($inst.log)" } @@ -832,7 +849,7 @@ try { foreach ($v in @($vendors.Values)) { $seedChange = $false foreach ($inst in $v.instances) { - if ($inst.proc -and $inst.proc.HasExited -and $inst.proc.ExitCode -eq 42) { $seedChange = $true } + if ($inst.proc -and $inst.proc.HasExited -and (Get-ExitCode $inst) -eq 42) { $seedChange = $true } } if ($seedChange) { # The whole vendor group restarts: the worker exe cannot be rebuilt while another identity still runs it @@ -861,7 +878,7 @@ try { foreach ($inst in $v.instances) { if ($inst.proc -and $inst.proc.HasExited -and -not $inst.restartAt) { $inst.restarts += 1 - $inst.exitCode = $inst.proc.ExitCode + $inst.exitCode = Get-ExitCode $inst $inst.restartAt = (Get-Date).AddSeconds(10) Log "$($inst.label): miner exited unexpectedly with code $($inst.exitCode); restarting in 10 s (restart $($inst.restarts))" Add-Event "$($v.card) miner $($inst.index) stopped (code $($inst.exitCode)), restarting in 10 s" 'error'