Stop-DbaProcess - Skip system sessions instead of trying to kill them - #10729
Merged
Merged
Conversation
(do Stop-DbaProcess) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
andreasjordan
marked this pull request as ready for review
September 20, 2026 19:48
potatoqualitee
approved these changes
Sep 21, 2026
potatoqualitee
left a comment
Member
There was a problem hiding this comment.
Reviewed the complete command and test changes at this exact head, including system-session classification, pipeline and explicit-SPID paths, callers, discussions, and passing integration CI. No material defects found.
Member
|
merci 馃檹馃徏 |
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.
Summary
Stop-DbaProcesscalledKillProcessfor every sessionGet-DbaProcessreturned, system sessions included. SQL Server refuses those with "Only user processes can be killed", so each of them ended in aCouldn't kill spid Nwarning, and that warning reaches the caller's-WarningVariableeven through-WarningAction SilentlyContinue.Until SQL Server 2022 this was mostly invisible, because system sessions sat below spid 50 and in
master, where nobody aims aStop-DbaProcess -Databaseat them. SQL Server 2025 parks system workers such as the "DB MIRROR" tasks above spid 50 and in user databases. On the lab's clustered SQL Server 2025 instance (FCI01) a "DB MIRROR" worker born by a mirroring test stayed in whatever user database was current, and from then on every restore of an existing database (Invoke-DbaAdvancedRestorekills the sessions of the database first, with-WarningAction SilentlyContinue) and every test that clears the sessions of its database before dropping it got the warning:Restore-DbaDatabase.Tests.ps1failed three$WarnVar | Should -BeNullOrEmptyassertions andSet-DbaDbCompression.Tests.ps1failed itsAfterAllunderEnableException.Get-DbaProcessalready reportsIsSystem, which matchesis_user_process = 0(checked on FCI01: the 29 system sessions above spid 50 are exactly the sessions withIsSystem = True).Stop-DbaProcessnow skips those with a verbose message, the way it already skips its own spid. Nothing changes for user sessions, and the callers inInvoke-DbaAdvancedRestoreneed no change: theALTER DATABASE ... WITH ROLLBACK IMMEDIATEthat follows the kill handles whatever is left.Test plan
Stop-DbaProcess.Tests.ps1: a system session of the instance piped in and selected by-Spidproduces no output and no warning. Every instance has system sessions, so this runs on every lane.developmentwith theCouldn't kill spidwarning in$WarnVar.Restore-DbaDatabase.Tests.ps1andSet-DbaDbCompression.Tests.ps1under the FCI configuration on PowerShell 7 (the two files that reproduced the failure alone).Stop-DbaProcess.Tests.ps1green on PowerShell 7 and Windows PowerShell 5.1.created by Claude and reviewed by Andreas Jordan
馃 Generated with Claude Code