Skip to content

Return retry task from async XML enclave execution - #5117

Merged
saurabh500 merged 5 commits into
mainfrom
dev/cheena/fix-async-ae-enclave-test-failures
Nov 23, 2026
Merged

saurabh500 merged 5 commits into
mainfrom
dev/cheena/fix-async-ae-enclave-test-failures

Conversation

@cheenamalhotra

@cheenamalhotra cheenamalhotra commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Testing only. Do not merge. The fix ships in #5085.

Description

Fixes the internal pipeline failures in ApiShould.TestEnclaveExecutionApis. The test's ExecuteXmlReaderAsync step fails with Internal connection fatal error. Error state: 15, Token: 1 (other runs show tokens 0, 70 and 88). On Linux the same step fails with Invalid command sent to ExecuteXmlReader. The command must return an Xml result., and then the test host crashes.

Root cause

BeginExecuteXmlReaderInternal returned localCompletion, which is the first attempt's task. When the enclave session is invalid, the driver runs an internal End and retries. The caller's End then ran on the first attempt at the same time as the retry, using the same state object. Depending on timing, the caller's End either parsed the retry's TDS stream midway (state 15) or got a reader with no metadata yet (NonXmlResult). The retry then kept running on a connection the test had already disposed.

The bug is already on main and isn't caused by the async Always Encrypted stack. #4887 added the test that exposes it, and an internal build from before #5079 and #5080 (193347) already failed the same way.

Fix

Return globalCompletion and attach the callback to it, matching Reader and NonQuery. Callers now see only the retry's result.

This is the same fix as aa9fadb in #5085, moved to main. #4585 and #5085 already include it.

Issues

Fixes the TestEnclaveExecutionApis failures in internal AE runs (builds 193347 and 193466).

Testing

  • Added SqlCommandEnclaveAsyncTests.BeginExecuteXmlReader_InvalidEnclaveSession_CompletesWithRetry. The simulated server returns error 33195, which triggers the internal End retry, and then holds the retry. The test checks that the XML task is still pending during the retry (this fails without the fix), that it reports the retry's outcome, and that the command and connection stay reusable.
  • dotnet build of UnitTests for net10.0 and net462: passed, 0 warnings.
  • Not run locally: the new test uses SimulatedServer, which hangs on the macOS dev host because of a local socket issue. It needs CI and the internal AE run, where TestEnclaveExecutionApis needs an enclave-enabled server.

Guidelines

Please review the contribution guidelines before submitting a pull request:

BeginExecuteXmlReader returned localCompletion, so the user's End ran
on the first attempt while the internal End and enclave retry were
still using the same state object. That desynced the TDS stream
(Internal connection fatal error, state 15). Return globalCompletion,
like Reader and NonQuery.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:27
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board Nov 19, 2026
@cheenamalhotra
cheenamalhotra changed the base branch from dev/cheena/laughing-waffle to main November 19, 2026 16:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The regression test exercises the wrong retry path and would pass with the production fix reverted, leaving the intended task and callback completion behavior unverified.

1 open issue
What changed in this PR

This PR aligns asynchronous XML enclave execution with Reader and NonQuery by exposing the completion task that includes retries. It targets the premature End execution associated with TDS stream errors in enclave API tests.

Changes:

  • Returns the global completion task and attaches the XML callback to it.
  • Adds a simulated-server test intended to verify retry completion, error propagation, and cleanup.
  • Imports the encrypted-metadata command helper from #5081 for test setup.
File Description
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​Utilities/​QueryMetadataCacheTestCommands.cs Adds helpers for commands with encrypted parameter metadata.
src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​SqlCommandEnclaveAsyncTests.cs Adds XML enclave retry and cleanup assertions.
src/​Microsoft.Data.SqlClient/​src/​Microsoft/​Data/​SqlClient/​SqlCommand.Xml.cs Uses global completion for the returned task and callback.

Review effort: Balanced

Use a server 33195 response to trigger the internal End retry path and gate
the retry so the test fails if the result completes before the retry.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The retry test incorrectly expects the task to throw even though SQL error 50000 surfaces only in EndExecuteXmlReader, causing the test to fail and skip the remaining End and cleanup assertions.

1 open issue
1 resolved since last review

Review effort: Balanced

The retry skips the internal End, so its task completes successfully and End reports the error.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 16:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The test sends an encryption-description RPC that the simulated server cannot decode, preventing it from reaching the intended retry and causing RetryEntered.Wait to fail even with the production fix.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Simulated server cannot handle parameter-encryption describe RPC

src/​Microsoft.Data.SqlClient/​tests/​UnitTests/​SimulatedServerTests/​SqlCommandEnclaveAsyncTests.cs:670

Provider.CacheHit = true skips attestation, but this enclave-enabled command still sends sp_describe_parameter_encryption before executing the query (SqlCommand.Encryption.cs:1402–1459). The simulated server cannot decode RPC packets (TDSMessage.cs:286–325), so the test cannot reach the gated retry and RetryEntered.Wait fails even with the production fix. Arrange preparation that the simulated server supports, or add describe-RPC handling, while preserving the server-error-triggered internal-End retry this test needs to exercise.

1 resolved since last review

Review effort: Balanced

@cheenamalhotra cheenamalhotra changed the title Return retry task from async XML enclave execution [Test only] Return retry task from async XML enclave execution Nov 19, 2026
The CE enclave command sends sp_describe_parameter_encryption as an RPC,
which the TDS test server could not parse. Add minimal RPC routing and
answer it with an empty response in the retry test engine.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The enclave retry/End concurrency change still needs current-head simulated-server CI and enclave-enabled integration validation to establish TDS stream safety.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 17:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shared async retry ownership and XML completion-ordering changes still need simulated-server and enclave runtime validation to confirm retry accounting, task ordering, and connection cleanup.

No open issues 🎉

Review effort: Balanced

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.58%. Comparing base (17bef7b) to head (a44681e).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5117      +/-   ##
==========================================
+ Coverage   68.99%   72.58%   +3.59%     
==========================================
  Files         314      315       +1     
  Lines       45857    74709   +28852     
==========================================
+ Hits        31638    54228   +22590     
- Misses      14219    20481    +6262     
Flag Coverage Δ
CI-SqlClient 71.19% <100.00%> (+2.19%) ⬆️
sqlclient-pr 72.29% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

cheenamalhotra added a commit that referenced this pull request Nov 19, 2026
@benrr101
benrr101 marked this pull request as ready for review November 23, 2026 22:41
@benrr101
benrr101 requested a review from a team as a code owner November 23, 2026 22:41
@benrr101 benrr101 added this to the 8.1.0-preview1 milestone Nov 23, 2026
@benrr101 benrr101 added the Hotfix 8.0.0 PRs that must be backported to release/8.0 label Nov 23, 2026
@benrr101 benrr101 moved this from To triage to In review in SqlClient Board Nov 23, 2026
@saurabh500
saurabh500 enabled auto-merge (squash) November 23, 2026 22:45
@saurabh500 saurabh500 changed the title [Test only] Return retry task from async XML enclave execution Return retry task from async XML enclave execution Nov 23, 2026
@saurabh500
saurabh500 merged commit 329df05 into main Nov 23, 2026
173 of 177 checks passed
@saurabh500
saurabh500 deleted the dev/cheena/fix-async-ae-enclave-test-failures branch November 23, 2026 23:30
@github-project-automation github-project-automation Bot moved this from In review to Done in SqlClient Board Nov 23, 2026
benrr101 pushed a commit that referenced this pull request Nov 24, 2026
#5136)

* Return retry task from async XML enclave execution

BeginExecuteXmlReader returned localCompletion, so the user's End ran
on the first attempt while the internal End and enclave retry were
still using the same state object. That desynced the TDS stream
(Internal connection fatal error, state 15). Return globalCompletion,
like Reader and NonQuery.



* Test internal-End enclave retry for BeginExecuteXmlReader

Use a server 33195 response to trigger the internal End retry path and gate
the retry so the test fails if the result completes before the retry.



* Await XML retry task before checking End error

The retry skips the internal End, so its task completes successfully and End reports the error.



* Handle describe RPC in simulated enclave XML retry test

The CE enclave command sends sp_describe_parameter_encryption as an RPC,
which the TDS test server could not parse. Add minimal RPC routing and
answer it with an empty response in the retry test engine.



* Release original async reservation after successful internal retry



---------

Co-authored-by: Cheena Malhotra <[email protected]>
Co-authored-by: Copilot App <[email protected]>
This was referenced Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hotfix 8.0.0 PRs that must be backported to release/8.0

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants