Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Proposed changes

The TrustList class only supported synchronous OnCall callbacks, forcing async operations to block with .GetAwaiter().GetResult(). This adds native async support via OnCallAsync handlers while maintaining backward compatibility.

Following feedback from @romanett, the implementation uses async as the core with sync wrappers, rather than separate sync and async implementations.

Key changes:

  • Async methods are the core implementation (OpenCoreAsync, ReadAsync, WriteAsync, CloseAsync, CloseAndUpdateAsync, AddCertificateAsync, RemoveCertificateAsync)
  • Sync methods are lightweight wrappers that call .AsTask().ConfigureAwait(false).GetAwaiter().GetResult() on async core
  • Both sync and async callbacks registered in constructor - generated code automatically prefers async when available
  • Replaced blocking .GetAwaiter().GetResult() patterns in async code paths with proper await and ConfigureAwait(false)
  • Proper CancellationToken propagation throughout all async operations
  • Helper methods (UpdateStoreCertificatesAsync, UpdateStoreCrlsAsync) updated to accept and propagate CancellationToken

Implementation pattern:

// Constructor registers both callbacks
node.Open.OnCall = new OpenMethodStateMethodCallHandler(Open);
node.Open.OnCallAsync = new OpenMethodStateMethodAsyncCallHandler(OpenAsync);

// Sync wrapper calls async core with ConfigureAwait(false)
private ServiceResult Open(..., ref uint fileHandle)
{
    var result = OpenAsync(..., CancellationToken.None)
        .AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
    fileHandle = result.FileHandle;
    return result.ServiceResult;
}

// Async core uses proper await
private async ValueTask<OpenMethodStateResult> OpenCoreAsync(...)
{
    X509Certificate2Collection certificates = await store.EnumerateAsync(cancellationToken)
        .ConfigureAwait(false);
    // Process certificates...
}

Types of changes

  • Enhancement (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

The implementation follows an async-core pattern where:

  • Async methods contain the actual implementation logic using proper await
  • Sync methods are thin wrappers using .AsTask().ConfigureAwait(false).GetAwaiter().GetResult() to prevent deadlocks
  • Stream operations (Read/Write) return ValueTask directly for efficiency since MemoryStream operations are inherently synchronous
  • All async certificate store operations properly propagate CancellationToken for proper cancellation support

This approach provides clean async code paths while maintaining full backward compatibility for existing code using sync callbacks.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Server] Make default TrustList Implemenation support async Callback OnCallAsync in addtion to OnCall</issue_title>
<issue_description>The default TrustList implementation in the Server Library should use the native Callbacks to Async code present in the generated classes (OnCallAsync). To not break users still relying on the sync callbacks the TrustList class shall be extended to support both the Sync Callbacks and Async callbacks ensuring proper usage of async Code.

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 3 commits January 17, 2026 16:54
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Copilot AI changed the title [WIP] Extend TrustList implementation to support async callbacks Add async callback support to TrustList implementation Jan 17, 2026
Copilot AI requested a review from romanett January 17, 2026 17:11
@romanett
Copy link
Contributor

@copilot instead of adding completely new async versions update the internals of the sync version to be async and make a sync wrapper using the .AsTask().GetAwaiter().GetResult() pattern.

Based on feedback, changed approach:
- Make internal implementation async (OpenCoreAsync, etc.)
- Sync methods now wrap async using .AsTask().GetAwaiter().GetResult()
- Both OnCall and OnCallAsync handlers registered
- Eliminates .GetAwaiter().GetResult() in async paths

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot instead of adding completely new async versions update the internals of the sync version to be async and make a sync wrapper using the .AsTask().GetAwaiter().GetResult() pattern.

Refactored the implementation as requested. The async methods are now the core implementation, and sync methods wrap them using .AsTask().GetAwaiter().GetResult(). Both OnCall and OnCallAsync handlers are registered. Changes in commit 714b4ea.

Copilot AI and others added 2 commits January 17, 2026 17:34
Prevents potential deadlocks by adding ConfigureAwait(false) before GetAwaiter().GetResult() in all sync wrapper methods. Also made the pattern consistent across all methods.

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Updated UpdateStoreCertificatesAsync and UpdateStoreCrlsAsync to properly propagate CancellationToken through all async operations. Ensures consistent async patterns throughout the implementation.

Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
@marcschier marcschier marked this pull request as ready for review January 20, 2026 12:46
@marcschier marcschier merged commit d71ee2a into master Jan 20, 2026
111 of 112 checks passed
@romanett romanett deleted the copilot/extend-trustlist-for-async-callbacks branch January 20, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Server] Make default TrustList Implemenation support async Callback OnCallAsync in addtion to OnCall

4 participants