Skip to content

Feature | Async friendly Always Encrypted support #3672

Open
0 of 2 issues completed
Open

Description

@cheenamalhotra

Always Encrypted types today don't support async APIs in base class as well as in implementations, leading to sync-over-async in Async workflows. This gap is important to fill for a true async workflow experience when executing commands where encryption/decryption is needed to be performed.

This will be covered in following tasks:

Implementation PRs

Key-store integration split

The changes in #4585 have been split into five stacked PRs. Each PR targets the preceding layer; the first targets main. Tests stay with the behavior they protect.

Layer Scope PR
1 Async symmetric-key cache: same-key deduplication, independent-key concurrency, sync-provider compatibility, cancellation, and cache publication #5077 (merged)
2 Async cryptographic utilities: CEK decryption, provider dispatch, candidate-key fallback, and CMK signature verification #5079 (merged)
3 Parameter discovery: shared describe parsing, deferred key operations, Reader/NonQuery/XML cancellation and cleanup #5080 (merged)
4 Query-metadata cache: async key loading, cancellation without eviction, and stale-cache fallback #5081 (open, in review; now targets main)
5 Enclave-package key loading: async package generation, connection revalidation, and bounded retries #5085 (open, in review)

Earlier layers are foundations, not individually the complete end-to-end feature. The cumulative split will be checked against #4585 before it is treated as the replacement. Existing async attestation work is already on main and is not being reintroduced.

Remaining integration gaps

End-to-end enclave-server validation and overall test coverage remain incomplete.

Design: shared sync/async workflow

Each internal sync/async pair now has one implementation: no Async suffix, it returns
ValueTask, and it takes bool isAsync followed by the CancellationToken. Sync callers pass
isAsync: false and call .GetAwaiter().GetResult(). Async callers await it. The code splits
only at the leaf I/O call, shown in orange below.

flowchart TD
    A["ExecuteReader / NonQuery / Xml<br/>(sync and async)"] --> TG["TryGetCachedQueryMetadata<br/>(probe cache once)"]
    TG --> RW["RunExecuteReaderWithEncryption<br/>(sync: inline; async: Task.Run, holds in-progress flag until TDS write)"]
    RW --> RC["RunExecuteReaderWithEncryptionCore<br/>(shared sync/async core)"]
    RC --> PP["PrepareForTransparentEncryption(metadata, retryConnection, isAsync, ct)<br/>returns Task"]
    PP -->|cache hit| C{"Keys or enclave keys<br/>to load?"}
    C -->|no| C1["TryCompleteCachedQueryMetadataInline"]
    C -->|yes| C2["CompleteCachedQueryMetadata(isAsync, ct)"]
    C2 -->|stale / enclave miss| D
    PP -->|cache miss| D["RunDescribeParameterEncryption(isAsync, ct)<br/>(attestation + sp_describe_parameter_encryption)"]
    D --> E["ReadDescribeEncryptionParameterResults(isAsync, ct)"]
    E --> E1["...Keys / ...Metadata / ...Attestation"]
    E1 --> F["CreateEnclaveSession(isAsync, ct)"]
    E1 --> G["DecryptSymmetricKey(isAsync, ct)"]
    C2 --> G
    RC --> P["GenerateEnclavePackage(isAsync, ct)<br/>then revalidate"]
    P -->|retryable package fault| RR["RetryEnclaveCommandAsync<br/>(invalidate session, retry once)"]
    RR --> RC
    P --> Q["EnclaveDelegate.GenerateEnclavePackage(isAsync, ct)"]
    Q --> S["GetDecryptedKeysToBeSentToEnclave(isAsync, ct)<br/>keys loaded one at a time"]
    S --> G
    G --> H["SymmetricKeyCache.GetKey -> LoadKey<br/>(per-key gate)"]
    G --> V["VerifyColumnMasterKeySignature(isAsync, ct)"]
    H --> L1["Gate: Wait / WaitAsync"]
    H --> L2["Provider: DecryptColumnEncryptionKey / ...Async"]
    V --> L3["Provider: VerifyColumnMasterKeyMetadata / ...Async"]
    F --> L4["EnclaveDelegate: CreateEnclaveSession / ...Async"]
    P --> T["RunExecuteReaderTds"]
    classDef leaf fill:#fde2c8,stroke:#d9822b;
    class L1,L2,L3,L4 leaf;
Loading

Notes:

  • Async work that ends in a blocking TDS write runs on a worker, never on the caller's thread
    or an SNI thread.
  • After each await, the command checks that the connection is still the same one: not closed
    or reopened, same database, same transaction. If the bound transaction completes while
    cached keys load, the command fails with a zombied-transaction error instead of running
    in autocommit. While the in-progress flag is set, reading SqlCommand.Transaction returns
    null without clearing the binding, so the zombied check still runs.
  • Sync and async share one prepare/execute core (RunExecuteReaderWithEncryptionCore); only the
    sync cache probe stays separate. PrepareForTransparentEncryption returns a Task and branches
    on isAsync only at I/O and revalidation points.
  • The async coordinator dispatches the core with Task.Run. It sets _enclaveAttestationInProgress
    before dispatch (and before the cache probe) and clears it in one finally after the TDS
    write/setup or on failure. The flag blocks changes to the command while work is pending.
  • If enclave package generation fails before results are read, RetryEnclaveCommandAsync
    invalidates the enclave session and retries once, in the task pipeline. It does not retry on
    cancellation or non-retryable errors. The coordinator hands the in-progress flag to the retry
    handler, which holds it during invalidation and clears it just before the retry attempt sets
    it again. A successful retry releases the first attempt's
    async-command reservation, and XML Begin/End returns the retry's completion.
  • [Async AE 5] Load enclave keys asynchronously and route package retries #5085 (layer 5) adds async loading of keys sent to the enclave on top of this; its merge of
    the unified [Async AE 4] Complete query metadata cache asynchronously #5081 design is in progress.

Follow-ups:

Sub-issues

Sub-issues

0 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added this to the 7.0.0 milestone on Oct 8, 2025
  2. moved this from To triage to Backlog in SqlClient Boardon Oct 16, 2025
  3. moved this from Backlog to In progress in SqlClient Boardon Oct 16, 2025
  4. added
    Approved
    and removed on Nov 19, 2025
  5. modified the milestones: 7.0.0-preview4, on Jan 20, 2026
  6. removed this from the milestone on Feb 12, 2026
  7. 15 remaining items

  8. priyankatiwari08 commented on Sep 17, 2026

    @priyankatiwari08
    Contributor

    /triage

  9. github-actions commented on Sep 17, 2026

    @github-actions

    🔍 Triage Summary (on-demand re-triage)

    Check Result
    Issue type Feature (tracking/epic issue with sub-tasks)
    Environment Not applicable — this is a feature/design tracking issue, not a bug report
    Area Area\AKV Provider (Always Encrypted enclave providers and encryption/decryption async path)
    Duplicates None found — related but distinct: #4480 (enclave provider refactor), #4425 (AE modernisation/optimisation)
    Regression Not applicable

    Analysis

    This is a milestone-tracked (8.0.0) feature/epic issue to eliminate sync-over-async behavior in Always Encrypted (AE) workflows by adding true async counterparts across the base classes, key store providers, and enclave provider implementations (NoneAttestationEnclaveProvider, AzureAttestationEnclaveProvider, VirtualizationBasedSecurityEnclaveProviderBase). Two of the linked sub-tasks (#3673, #4540, #4541) are already merged/closed, and the remaining work is enclave provider async implementations, wiring async APIs into async code paths, and adding test coverage. This is a design-sensitive, internally-maintained effort (per @mdaigle's comment) — not yet open to external contribution. Severity: P2 (planned engineering improvement, not a defect).

    Next Steps

    • No environment validation needed since this is a feature/epic, not a bug.
    • Recommend keeping this issue as internally driven per @mdaigle's earlier comment; external contribution (e.g. from @RutulPatel8) should wait until the internal design discussion for enclave provider async support concludes, to avoid conflicting approaches to Task.FromResult-based fallbacks vs. true async implementations.
    • Suggest cross-linking Refactor enclave providers to separate enclave-type from attestation-mechanism (composition over inheritance) #4480 (enclave provider refactor) since both issues touch NoneAttestationEnclaveProvider/AzureAttestationEnclaveProvider/VirtualizationBasedSecurityEnclaveProviderBase — sequencing these two efforts (refactor vs. async support) could reduce merge conflicts and duplicated work.
    • Continue tracking remaining checklist items (enclave provider async implementations, async code path wiring, testing/coverage) as sub-issues or PRs linked to this tracking issue.

    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 #3672 · copilot · auto · 43.4 AIC · ⌖ 13.1 AIC · ⊞ 11.9K · ◷

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

Metadata

Metadata

Labels

Approved

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions