Restart container before restoring demo data snapshot to free DB connections#8931
Open
aholstrup1 wants to merge 1 commit into
Open
Restart container before restoring demo data snapshot to free DB connections#8931aholstrup1 wants to merge 1 commit into
aholstrup1 wants to merge 1 commit into
Conversation
…ections The demo-data retry restore failed with 'Exclusive access could not be obtained because the database is in use' because Stop-NAVServerInstance returns before the deadlocked NAV session's SQL connection drains. Restart the container first so the restore can obtain exclusive access on 'default'.
Contributor
Copilot PR ReviewIteration 1 · Outcome: not-applicable
Knowledge source: https://github.com/microsoft/BCQuality@822cae1b2771ac25f665f73369f69093bd4fd630 No findings were posted for this iteration. Orchestrator pre-filter (13 file(s) excluded)
Findings produced by the Copilot CLI agent against BCQuality at |
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.
What & why
CI runs that hit a transient deadlock during demo data generation were failing permanently instead of recovering. The demo-data retry logic (added in #8848) snapshots the tenant DB and restores it before re-attempting generation, but the restore itself died with:
Root cause: a failed generation attempt leaves a deadlocked/rolling-back NAV session whose SQL connection does not drain in time.
Stop-NAVServerInstancereturns before that connection is gone, soRestore-SqlDatabase ... -ReplaceDatabasecan't get exclusive access todefault. Because the deadlock reproduces consistently in some builds, the broken recovery path turned a recoverable retry into a guaranteed failure on every rerun.This change restarts the container at the start of
Restore-TenantDatabaseForDemoDataRetry. The restart forcibly terminates the SQL Server process (dropping every connection todefault); NAV comes back idle, so the subsequent stop drains cleanly and the restore obtains exclusive access. The restore is still required afterward to discard the partial demo data the failed attempt left behind; the restart only clears connections, not data.This only affects the recovery path, so the extra restart time is paid only when a generation attempt has already failed. The happy path is unchanged.
Linked work
AB#640951
How I validated this
What I tested and the outcome
Build-script (PowerShell) change only, no AL app changes. Verified the script parses with no errors. The fix targets the CI demo-data import path; validation is via the affected pipeline reaching the restore-and-retry path successfully. No automated tests exist for this container/SQL orchestration script.
Risk & compatibility
Low risk and confined to the demo-data retry recovery path used during CI test-data import. Adds a container restart (a few minutes) only when a generation attempt fails. The retry snapshot
.baklives inside the container filesystem, which a restart (not a recreate) preserves, so the subsequent restore still finds it.