Skip to content

Commit

Permalink
(GH-883) Wait Up to 15 Seconds for Process Exit
Browse files Browse the repository at this point in the history
Even though `$process.WaitForExit()` has identified that the process
has exited, it appears that the process may be performing some final
cleanup as the exit code is still null when it is passed to
`Set-PowerShellExitCode`. Allow the process to take up to 15 seconds to
fully exit so that it has cleaned up. In the case of 7zip, ensure that
it has ample time to finish extracting after it has indicated that it
has completed the extraction and is exiting.
  • Loading branch information
ferventcoder committed Aug 1, 2016
1 parent 5401fba commit 04d9e0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,16 @@ param(
Unregister-Event -SourceIdentifier "LogErrors_ChocolateyZipProc"

# sometimes the process hasn't fully exited yet.
Start-Sleep 1
for ($loopCount=1; $loopCount -le 15; $loopCount++) {
if ($process.HasExited) { break; }
Write-Debug "Waiting for 7z.exe process to exit - $loopCount/15 seconds";
Start-Sleep 1;
}

$exitCode = $process.ExitCode
Set-PowerShellExitCode $exitCode
$process.Dispose()

Set-PowerShellExitCode $exitCode
Write-Debug "Command ['$7zip' $params] exited with `'$exitCode`'."

if ($zipExtractLogFullPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ Elevating Permissions and running [`"$exeToRun`" $wrappedStatements]. This may t
Unregister-Event -SourceIdentifier "LogErrors_ChocolateyProc"

# sometimes the process hasn't fully exited yet.
Start-Sleep 1
for ($loopCount=1; $loopCount -le 15; $loopCount++) {
if ($process.HasExited) { break; }
Write-Debug "Waiting for process to exit - $loopCount/15 seconds";
Start-Sleep 1;
}

$exitCode = $process.ExitCode
$process.Dispose()
Expand All @@ -218,7 +222,7 @@ Elevating Permissions and running [`"$exeToRun`" $wrappedStatements]. This may t
} else {
$chocoSuccessCodes = @(0, 1605, 1614, 1641, 3010)
if ($chocoSuccessCodes -notcontains $exitCode) {
Write-Warning "Exit code '$exitCode' was considered valid, but not as a choco success code. Returning 0"
Write-Warning "Exit code '$exitCode' was considered valid by script, but not as a Chocolatey success code. Returning '0'."
$exitCode = 0
}
}
Expand Down

0 comments on commit 04d9e0e

Please sign in to comment.