Repository navigation
Progress - Complete the bars of 9 more commands in finally blocks (tier 2) - #10774
Open
andreasjordan wants to merge 9 commits into
Open
andreasjordan wants to merge 9 commits into
andreasjordan wants to merge 9 commits into
Conversation
The bar of a database (Id 1) and the bar of its backup files (Id 2) were completed after the loop over the backup files. A throw, a stopped pipeline and Select-Object -First at the result of a file skipped both. The child bar is now completed first thing in the finally of each file's restore, before the output there, and the loop over the files runs in try/finally, whose finally completes the bar of the database. (do Invoke-DbaAdvancedRestore) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar was completed after the loop that collects the results of the threads. A throw, a stopped pipeline and Select-Object -First at the first header row skipped it. The loop now runs in try/finally and the finally completes the bar. (do Read-DbaBackupHeader) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar was drawn in the process block and completed in the end block, which neither Select-Object -First nor a stopped pipeline reaches. The loop over the instances now runs in try/finally and the finally completes the bar; the end block held only that completion and goes away. (do Invoke-DbaDiagnosticQuery) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar was completed after the last migration step only. A throw in one of the steps or a stopped pipeline left it on screen. The steps now run in try/finally and the finally completes the bar. (do Start-DbaMigration) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar of each availability group was completed after the last sync step only. A throw in one of the steps or a stopped pipeline left it on screen. The steps now run in try/finally and the finally completes the bar. (do Sync-DbaAvailabilityGroup) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar of each database was completed after the loop over its users. A throw, a stopped pipeline and Select-Object -First at the first script or file skipped it. The loop now runs in try/finally and the finally completes the bar. (do Export-DbaUser) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar was completed after the loop over the databases. The returns inside the loop, a throw, a stopped pipeline and Select-Object -First at the result of a table skipped it. The loop now runs in try/finally and the finally completes the bar. (do Invoke-DbaDbDataGenerator) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar of each instance was completed after the loop over the databases. A throw or a stopped pipeline, likely during a long scan, left it on screen. The loop now runs in try/finally and the finally completes the bar. (do Invoke-DbaDbPiiScan) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar of the databases (Id 1) and the bar of the growth (Id 2) were never completed, not even after a run that worked; the only completion completed the bar of the databases when a log backup failed. The growth loop, the log backup and the loop over the databases now each run in try/finally, and each finally completes its own bar. The completion of the parent on a failed backup goes away. The completion after the backup stays, because the shrink follows it. (do Expand-DbaDbLogFile) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 5, 2026
andreasjordan
marked this pull request as ready for review
October 5, 2026 17:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of RFC #10548: the
try/finallyleak fixes, tier 2 of 3. Same pattern as #10773 (tier 1), one commit per command with its test. Independent of #10773.Problem
These 9 commands complete their progress bar only on the success path, so a throw under
-EnableException, a stopped pipeline (Ctrl+C) orSelect-Object -Firstleft the bar on screen for the rest of the session. Two of them were worse:processand completed it inend, which neitherSelect-Object -Firstnor a stopped pipeline reaches.Change
Each bar's completion moves into a
finallyaround that bar's lifetime.finallyof each file's restore, before the output there (a downstreamSelect-Object -Firststops at that output). The loop over the files runs intry/finally, whosefinallycompletes the parent. The success-path completion of the child stays, because a stop-at-mark restore still runs the recovery statement after it.try/finally, eachfinallycompletes its own bar, children inside their parent. The completion of the parent on a failed backup goes away. The completion of the backup bar after the backup stays, because the shrink follows it.try/finally. Its counter restarts per instance, so the bar's lifetime is that loop. Theendblock held only the completion and goes away.try/finallyaround the loop or the steps that draw the bar.Most of the diff is re-indentation:
git diff -wshows 38 lines added and 5 removed for the 9 commands.Test
Same boundary as in #10773: the real command runs in a runspace of its own, created by the PowerShell API without a host, where
Write-Progressputs every record intoStreams.Progress. The test asserts that the command drew its bar and that no progress Id is left whose last record is not a completed one.Select-Object -First 1stops after the full backup (asserted)Select-Object -First 1at its result-WhatIf, pipeline stopped at the first migration step-WhatIf, pipeline stopped at the first step-Passthru,Select-Object -First 1at the scriptSelect-Object -First 1at the result of the tableRead-DbaBackupHeader runs its threads in a runspace pool on
$Host, and once a thread has run there, the warning, verbose and progress records of the calling pipeline no longer reach theStreamsof an API host, so its bar cannot be seen this way (same as the-Parallelbar of Start-DbaDbEncryption in #10773). I checked it in a real console window instead, reading the ConsoleHost's pending bars by reflection afterRead-DbaBackupHeader ... | Select-Object -First 1: the old command leaves "Updating" (Id 1) behind on 5.1 and 7.6, the new one does not. Its existing tests pass.Results (lab, InstanceSingle SQL Server 2019, Copy1 2022, Copy2 2025):
TestTestfiles.Tests.ps1andTestTestLayout.ps1report nothing for the 8 changed test files.Left open
[Runspace]::DefaultRunspacewhen it is stopped. Same.馃 Generated with Claude Code