Repository navigation
Progress - Complete the bars of 13 more commands in finally blocks (tier 3) - #10775
Open
andreasjordan wants to merge 13 commits into
Open
andreasjordan wants to merge 13 commits into
andreasjordan wants to merge 13 commits into
Conversation
The sequential bar was completed after the loop over the databases, the bar that waits for the -Parallel threads after the retrieval loop. A throw, a stopped pipeline and Select-Object -First skipped both. Each loop now runs in try/finally and its finally completes its own bar. (do Stop-DbaDbEncryption) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar is drawn while the command waits for the decryption and was completed after that wait only. A throw or a stopped pipeline during the wait left it on screen. The wait now runs in try/finally and the finally completes the bar. (do Disable-DbaDbEncryption) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar of each destination was completed after the loop over the logins, at the end of the try that already restores the database context. A throw, a stopped pipeline and Select-Object -First at the result of a login skipped it. The completion moves into the finally of that try. (do Sync-DbaLoginPermission) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar was completed after the loop over the instances only. A throw, a stopped pipeline during the long publish of the dacpac and Select-Object -First at the result skipped it. The loop now runs in try/finally and the finally completes the bar. (do Install-DbaSqlWatch) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… block The bar of each instance was completed at the end of its loop iteration. The Stop-Function -Continue when the remote call fails, a throw and Select-Object -First at the result skipped it. The steps from the first bar on now run in try/finally and the finally completes the bar. (do Remove-DbaNetworkCertificate) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y block The bar was completed after the loop over the scripts and by hand in the catch. A stopped pipeline during a download and Select-Object -First at the first saved file skipped it. The loop now runs in try/finally and the finally completes the bar; the completion in the catch goes away. (do Save-DbaDiagnosticQueryScript) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar was completed by hand in five places. A stopped pipeline while the NuGet packages were resolved and downloaded, or an exception outside the existing try, left it on screen. The work from the first progress step on now runs in try/finally and the finally completes the bar; the five hand-written completions go away. (do Install-DbaParquet) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bar of a download was completed after Invoke-WebRequest only. A failed download ends just that statement, so the completion still ran, but with -ErrorAction Stop of the caller the failure throws out of the command, and a stopped pipeline during the download ends it as well; both left the bar on screen. Each of the two downloads now runs in try/finally and the finally completes its bar. (do Save-DbaKbUpdate) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lock The bar was completed after the information was collected. A throw or a stopped pipeline during the collection left it on screen. The collection now runs in try/finally and the finally completes the bar. (do New-DbatoolsSupportPackage) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in a finally block The bar of each computer was completed after the files were returned. A throw, a stopped pipeline and Select-Object -First at the first file skipped it. The work on each computer now runs in try/finally and the finally completes the bar. (do New-DbaComputerCertificateSigningRequest) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a finally block The bar of the internal Get-SqlFileStructure was completed after its loop over the databases. A throw inside the loop left it on screen. The loop now runs in try/finally and the finally completes the bar. (do Copy-DbaDatabase) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…finally block The bar of the full scan behind -DetectColumnTypes (Id 2) was completed after the scan only. A stopped pipeline or a failing scan left it on screen. The scan now runs in try/finally and the finally completes the bar. (do Import-DbaCsv) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nally block The internal Test-SqlInstance completed the bar of a computer after the scan of that computer. A throw or a stopped pipeline during the scan, which can take seconds per computer, left it on screen. The scan now runs in try/finally and the finally completes the bar. (do Find-DbaInstance) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 3 of 3 (the commands with few or noStop-Functioncalls inside the bar's lifetime). Same pattern as #10773 and #10774, one commit per command with its test. Independent of both.Problem
These 13 functions complete their progress bar only on the success path, so a throw, a stopped pipeline (Ctrl+C) or
Select-Object -Firstleft the bar on screen for the rest of the session. Three of them are internal functions nested in a public command: Get-SqlFileStructure in Copy-DbaDatabase, Get-InferredSchema in Import-DbaCsv (the full scan of-DetectColumnTypes) and Test-SqlInstance in Find-DbaInstance.Change
Each bar's completion moves into a
finallyaround that bar's lifetime.-Parallelthreads (Id 1). Each gets its ownfinally, as in Start-DbaDbEncryption in Progress - Complete the bars of 13 long-running commands in finally blocks (tier 1) #10773.try/finallyto restore the database context; the completion moves into thatfinally.try/finally.try/finallyaround the loop or the steps that draw the bar.Most of the diff is re-indentation:
git diff -wshows 45 lines added and 11 removed for the 13 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 1at the first database, which the earlier contexts left not encryptedSelect-Object -First 1at the result of the loginSelect-Object -First 1at the result; a certificate that was configured is put backSelect-Object -First 1at the first downloaded script-Forceinto the test drive, pipeline stopped at the first record (while NuGet is resolved).invalidand-ErrorAction Stop, so the failed download throws out of the command; needs neither the catalog nor the internet. Without-ErrorAction Stopthe old code completed the bar as well: Invoke-WebRequest reports the failure as an error that ends only its own statement, so the next line still ranSelect-Object -First 1at the first file; the request is removed from LocalMachine\REQUEST like the others-DetectColumnTypes, pipeline stopped at the first record of the type detectionNo automated test for two of them:
TRACEOFFuntil the scan is restarted), but it works for the whole instance, and a run that dies betweenTRACEONandTRACEOFFwould leave every later TDE test waiting.ALTER DATABASE ... SET ENCRYPTION SUSPENDper database does not help: the decryption is done before it can be suspended, and SMO issues theALTERagain, which SQL Server refuses for a database whose encryption is already off. If a test with trace flag 5004 is wanted, I can add it.The existing tests of both pass.
The
-Parallelbar of Stop-DbaDbEncryption runs its threads in a runspace pool on$Host, like Start-DbaDbEncryption in #10773, so the API host does not see its records either. I checked it the same way, in a real console window afterStop-DbaDbEncryption -Parallel | Select-Object -First 1against one unencrypted test database: the old command leaves "Disabling encryption" (Id 1) behind on 5.1 and 7.6, the new one does not.Results (lab, InstanceSingle SQL Server 2019, Multi1 2025, Multi2/Restart 2022):
Remove-Item -Recurse) writes a completed record of its own for Id 0, which clears the leftover bar by accident; on 5.1 the bar stays.TestTestfiles.Tests.ps1andTestTestLayout.ps1report nothing for the 11 changed test files.Left open
🤖 Generated with Claude Code