Make SQL service restart in cert generation resilient to start-pending state - #274
Merged
Merged
Conversation
…g state Freshly-provisioned CI images can leave SQL Server in a start-pending state, so a plain Restart-Service intermittently fails with CouldNotStopService. Wait for a steady state, then stop/start with retries, and target the passed-in instance name instead of hardcoding MSSQLSERVER.
Contributor
There was a problem hiding this comment.
Pull request overview
Improves SQL Server certificate setup reliability during transient service states.
Changes:
- Adds retry-based SQL service restart logic.
- Uses the configured instance when resolving the service.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
Except the bot comment this looks good to go. |
Saurabh Singh (saurabh500)
approved these changes
Aug 13, 2026
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changesNo lines with coverage information in this diff. 🔗 Quick Links |
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
Fixes an intermittent CI failure in the Windows SQL setup step where
Generate-SqlCertificates.ps1fails withCouldNotStopService("service cannot be stopped"). On freshly-provisioned images SQL Server can still be in a start-pending state (startup database recovery) when the script tries to restart it to pick up the new TLS certificate thumbprint, and a plainRestart-Servicefails outright.Adds
Restart-SqlServiceSafely, which:RunningorStoppedbefore touching it,WaitForStatusand up to 5 retries,Also stops hardcoding
MSSQLSERVERas the service name: the service is now derived from the$instanceNamealready passed intoNew-And-Install-Certificates, mapping named instances toMSSQL$<instance>the same wayEnable-SqlProtocols.ps1andConfigure-ExtendedProtection.ps1do. Behavior is unchanged for the default instance.This change was split out of #142 so the flake fix can merge independently of the NVMe pool retarget.
Linked work item
None.
Testing
No local test run — this only executes on Windows CI agents with a real SQL Server service. Verification is a green Windows validation run; the failure mode it addresses is intermittent, so the signal is the absence of
CouldNotStopServicein the "Generate SQL certificates" step across runs.Breaking changes / migration notes
None. Script parameters and outputs are unchanged.