Repository navigation
Progress - Complete the bars of 9 more commands in finally blocks (tier 2) - #10774
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>
potatoqualitee
left a comment
There was a problem hiding this comment.
Reviewed at 8a05b63.
The progress cleanup scopes cover the relevant returns, exceptions, continuation paths, multiple-input paths, and early pipeline termination without changing the commands' existing work or loop targets. In particular, the restore child bar completes before its result is emitted, and log expansion completes nested bars before the database bar. Reviewed all 17 changed files, surrounding source and flow-control helpers, tests, CI, and existing discussions.
The eight new regression-test sections exercise real commands and verify that the relevant progress appeared and was subsequently completed. The ci-azure logs show all nine relevant command test files passing at this head; checks show 20 successes and one skipped legacy windows-tests job. Read-DbaBackupHeader's cancellation verification remains manual as documented. I did not rerun the SQL integration suite or that manual console test locally.
No material blocking defect found.
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