diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-08-18 03:45:53 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-18 03:45:53 +0300 |
| commit | d497ee14dd3f2b5325a16d0de779ed6bd62178ee (patch) | |
| tree | f8f96edd0eaa0fa7641387eceb659793dc566aba /scripts/windows_install_conpty_package_test.ps1 | |
| parent | b177acf014d57e8deaf0ba5934b9ddf5f252e8d6 (diff) | |
fix: retry Windows installer activation after transient locks (#2921)
refs #2916
Diffstat (limited to 'scripts/windows_install_conpty_package_test.ps1')
| -rw-r--r-- | scripts/windows_install_conpty_package_test.ps1 | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/windows_install_conpty_package_test.ps1 b/scripts/windows_install_conpty_package_test.ps1 index 4b0e73f3..95b31c4a 100644 --- a/scripts/windows_install_conpty_package_test.ps1 +++ b/scripts/windows_install_conpty_package_test.ps1 @@ -212,6 +212,64 @@ try { $manifest | Out-File -LiteralPath $manifestPath -Encoding utf8 $stagedConpty = Join-Path $releasesDir ".staging.$($releaseDir.Name).$PID\conpty\conpty.dll" + + $transientLockState = @{ Handle = $null; Acquired = $false; Released = $false } + $transientLockTimer = New-Object System.Timers.Timer + $transientLockTimer.Interval = 300 + $transientLockTimer.AutoReset = $false + $transientLockSource = "HerdrTransientInstallerLock-$PID" + $transientLockRelease = Register-ObjectEvent ` + -InputObject $transientLockTimer ` + -EventName Elapsed ` + -SourceIdentifier $transientLockSource ` + -MessageData $transientLockState ` + -Action { + $state = $event.MessageData + if ($null -ne $state.Handle) { + $state.Handle.Dispose() + $state.Handle = $null + } + $state.Released = $true + } + $lockStagedFileTransiently = { + if (-not $transientLockState.Acquired) { + $transientLockState.Handle = [System.IO.File]::Open( + $stagedConpty, + [System.IO.FileMode]::Open, + [System.IO.FileAccess]::Read, + [System.IO.FileShare]::Read + ) + $transientLockState.Acquired = $true + $transientLockTimer.Start() + } + }.GetNewClosure() + $transientLockBreakpoint = Set-PSBreakpoint -Script $installerPath -Variable "backupDir" -Mode Write -Action $lockStagedFileTransiently + try { + & "$PSScriptRoot\..\website\install.ps1" ` + -ManifestUrl $manifestUrl ` + -InstallDir $installDir ` + -ExpectedBuildId "installer-test" + if (-not $transientLockState.Acquired) { + throw "installer did not acquire the transient staged-file lock" + } + if (-not $transientLockState.Released) { + throw "installer activated the release before the transient lock was released" + } + if (-not (Test-Path -LiteralPath (Join-Path $releaseDir.FullName "conpty\conpty.dll") -PathType Leaf)) { + throw "installer did not repair the release after the transient lock cleared" + } + } finally { + Remove-PSBreakpoint -Breakpoint $transientLockBreakpoint + $transientLockTimer.Stop() + Unregister-Event -SourceIdentifier $transientLockSource -ErrorAction SilentlyContinue + Remove-Job -Id $transientLockRelease.Id -Force -ErrorAction SilentlyContinue + if ($null -ne $transientLockState.Handle) { + $transientLockState.Handle.Dispose() + } + $transientLockTimer.Dispose() + } + + Remove-Item -LiteralPath (Join-Path $releaseDir.FullName "conpty\conpty.dll") -Force $lockState = @{ Handle = $null } $lockStagedFile = { if ($null -eq $lockState.Handle) { |
