Repository navigation
New-DbaAvailabilityGroup - Complete the progress bar in a finally block - #10764
Merged
potatoqualitee merged 1 commit intoSep 30, 2026
Merged
Conversation
A stopped pipeline (Ctrl+C, for example while the command waits for the replicas) or an exception outside Stop-Function left the bar on screen. The process block now completes it in finally, which replaces the completions that were written before every Stop-Function. (do New-DbaAvailabilityGroup) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
andreasjordan
marked this pull request as ready for review
September 27, 2026 18:22
potatoqualitee
approved these changes
Sep 30, 2026
potatoqualitee
left a comment
Member
There was a problem hiding this comment.
Reviewed the complete exact-head patch, surrounding progress/control flow, real-boundary cancellation test, CI, and existing discussion. No material correctness, cleanup, compatibility, or multi-input defect found.
potatoqualitee
deleted the
new-dbaavailabilitygroup-progress-finally
branch
September 30, 2026 09:06
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 fix for New-DbaAvailabilityGroup. Independent of #10761, #10762 and #10763.Problem
New-DbaAvailabilityGroup completed its bar by hand: one
Write-Progress -Completedin front of each of the 20Stop-Functioncalls or early returns, and one at the end. That covers the throws ofStop-Functionunder-EnableException, but not a stopped pipeline and not an exception outsideStop-Function. A stopped pipeline is what Ctrl+C does, and the command is likely to be stopped while it waits for the replicas to connect. In both cases the bar stayed on screen for the rest of the script.Change
From the first progress step on, the
processblock runs intry/finally, and thefinallycompletes the bar. The 20 hand-written completions go away.Most of the diff is re-indentation:
git diff -wshows 4 lines added and 20 removed.Test
A new integration context runs the real command with
-WhatIf, so the instance stays unchanged. It runs in a runspace of its own, created by the PowerShell API without a host, whereWrite-Progressputs every record intoStreams.Progress. The test stops the pipeline as soon as the first record arrives, the same as Ctrl+C. It asserts that the run really was stopped (so a run that finished first cannot pass by accident) and that every progress Id got a completed record.-WhatIfrun would end after about 0.9 to 1.5 s, so the 10 ms poll leaves a wide margin.TestTestfiles.Tests.ps1andTestTestLayout.ps1report nothing for the file.🤖 Generated with Claude Code