Skip to content

Simplify async enclave execution state and retry handling #5114

Open

Description

@cheenamalhotra

Follow-up to #3672, after the five-layer split (#5077, #5079, #5080, #5081, #5085).

The async enclave execution path works, but its state handling is spread out and hard to
follow. Simplify it without changing behavior:

  • Give _enclaveAttestationInProgress one owner. It is set or cleared in four places today:
    CompleteParameterEncryptionAsync, PrepareForTransparentEncryption
    (inProgressFlagWasSet), PrepareForTransparentEncryptionAsync
    (ownsInProgressFlag/handedOff), and the reader, which sets it and has
    ContinueRunExecuteReaderTdsAsync clear it. Use one disposable scope created at reader entry.
  • Shorten ContinueRunExecuteReaderTdsAsync (16 parameters). Group the prepared connection,
    close count, database and retry connection into a struct with one Validate(method) method,
    replacing the repeated ValidateConnectionLifetime + ValidateConnectionForEnclaveExecution
    pairs.
  • Simplify SqlCommand.CreateLocalCompletionTask: pull out a ShouldRetry(exception, usedCache) helper instead of reaching the catch block through task.GetAwaiter().GetResult(),
    and turn the ContinueWith(async ...) lambda into a named async method.
  • Replace the three catch blocks in SqlCommand.GenerateEnclavePackage with one catch
    that uses an exception filter.
  • Move the setup shared by the SimulatedServer pending-package-key tests in
    SqlCommandEnclaveAsyncTests into a helper.

Existing unit and SimulatedServer tests should pass unchanged.

Activity

  1. added this to the 8.1.0-preview1 milestone on Nov 18, 2026
  2. moved this from To triage to Backlog in SqlClient Boardon Nov 18, 2026
  3. github-actions commented on Nov 18, 2026

    @github-actions

    🔍 Triage Summary

    Check Result
    Issue type Task (internal refactoring, no behavior change)
    Environment Not applicable (not a bug report)
    Area Area\Async (also Area\Always Encrypted, already applied)
    Duplicates None found; related parent: #3672
    Regression Not indicated

    Analysis

    This is a refactoring task that follows the five-layer split of async Always Encrypted support (#3672). It simplifies state ownership of _enclaveAttestationInProgress, the ContinueRunExecuteReaderTdsAsync signature, SqlCommand.CreateLocalCompletionTask retry handling, and GenerateEnclavePackage exception handling. Severity is P3: no behavior change is intended. The main risk is subtle changes to async state and retry semantics.

    Next Steps

    • Assign to Copilot coding agent or the existing assignee. Do the five checklist items as separate, reviewable commits, and keep the existing unit and SimulatedServer tests unchanged and passing.
    • Make the in-progress flag scope exception-safe and make sure it is released on every path (sync, async, hand-off, and retry).
    • Cover both sync and async paths, and re-run the enclave retry tests that exercise the cache-miss/retry flow.

    Note: This triage summary is auto-generated by an AI agent. The analysis and suggestions above have not been verified by a human maintainer. Please treat as preliminary guidance only.

    Generated by SqlClient Issue Auto-Triage for #5114 · copilot · auto · 15.6 AIC · ⌖ 11.3 AIC · ⊞ 7.8K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions