Repository navigation
Description
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:
- Introduce Async API counterparts for AE base class #3673
- Implement async APIs in Always Encrypted Azure Key Vault provider #4540
- Add async counterparts to the enclave provider hierarchy (Phase 3, partial) #4541
- Implement async counterparts in all Enclave provider implementations (Add async counterparts to the enclave provider hierarchy (Phase 3, partial) #4541):
- NoneAttestationEnclaveProvider
- AzureAttestationEnclaveProvider
- VirtualizationBasedSecurityEnclaveProviderBase
- Implement Async API usage in Async code paths
- Testing and code coverage
Implementation PRs
- Add asynchronous enclave delegate operations #4886 - Async enclave-delegate operations (merged).
- Await enclave attestation in asynchronous command execution #4887 - Async enclave attestation in command execution (merged).
- Use the async Always Encrypted key store APIs on async execution paths #4585 - Original combined key-store call-path integration PR (draft, retained as the reference for the five-layer split).
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
- Complete and review the five-layer key-store integration split above.
- Merge two fixes in [Async AE 5] Load enclave keys asynchronously and route package retries #5085 for bugs already on
main. Await enclave attestation in asynchronous command execution #4887'sApiShould.TestEnclaveExecutionApisexposed both:
Both fixes are validated by the test-only Return retry task from async XML enclave execution #5117 and are in [Async AE 5] Load enclave keys asynchronously and route package retries #5085 with a SimulatedServer regression test.- Async XML returned the first attempt's task instead of the retry's. The caller's End then raced the internal retry on the same connection and corrupted the TDS stream ("Internal connection fatal error, state 15").
- A successful internal retry never released the first attempt's async-command reservation. The next async command on a non-MARS connection then failed.
- Wire async key decryption into
SqlBulkCopyasync execution (CopyBatchesAsync->TdsParser.LoadColumnEncryptionKeyscurrently calls synchronousDecryptSymmetricKey). This pre-existing path is outside the split and remains follow-up work. - Run enclave-specific retry/reuse integration coverage with enclave-enabled server configuration; these cases were skipped in Use the async Always Encrypted key store APIs on async execution paths #4585 build 184898.
- Unify remaining sync/async pairs in the Always Encrypted command path #5113 - Unify remaining sync/async pairs in the Always Encrypted command path.
- Simplify async enclave execution state and retry handling #5114 - Simplify async enclave execution state and retry handling.
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;
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, readingSqlCommand.Transactionreturns
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.PrepareForTransparentEncryptionreturns aTaskand branches
onisAsynconly 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 onefinallyafter 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:
- Unify remaining sync/async pairs in the Always Encrypted command path #5113 - Unify the sync/async pairs that are still split (
EnclaveDelegate.CreateEnclaveSession*).
[Async AE 4] Complete query metadata cache asynchronously #5081 already merges thePrepareForTransparentEncryption*paths into onePrepareForTransparentEncryption. - Simplify async enclave execution state and retry handling #5114 - Simplify the retry and continuation code. [Async AE 4] Complete query metadata cache asynchronously #5081 now unifies sync/async execution and
owns enclave package retry, so the remaining scope should be re-checked once [Async AE 5] Load enclave keys asynchronously and route package retries #5085 merges it.
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity
15 remaining items
Implement async APIs in Always Encrypted Azure Key Vault provider (#4540
priyankatiwari08 commentedon Sep 17, 2026
/triage
github-actions commentedon Sep 17, 2026
🔍 Triage Summary (on-demand re-triage)
Area\AKV Provider(Always Encrypted enclave providers and encryption/decryption async path)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
@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 toTask.FromResult-based fallbacks vs. true async implementations.NoneAttestationEnclaveProvider/AzureAttestationEnclaveProvider/VirtualizationBasedSecurityEnclaveProviderBase— sequencing these two efforts (refactor vs. async support) could reduce merge conflicts and duplicated work.Bump Microsoft.Data.SqlClient from 6.1.6 to 7.1.0 (#66)
Bump the microsoft group with 11 updates (#1370)
Bump the nuget-ecosystem group with 6 updates (#16)
Bump the nuget-ecosystem group with 9 updates (#76)