You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix deadlocks in async-to-sync bridge by properly managing synchronization context
#2372
Async method calls through the synchronous RunSync bridge were causing deadlocks due to improper synchronization context management
Continuations were being queued to the thread pool instead of the custom synchronization context, breaking the synchronous execution model
The CustomSynchronizationContext implementation needed alignment with the proven Rebus library implementation pattern
Deliverables
Context Management: Move synchronization context setup/teardown from RunSync into CustomSynchronizationContext.Run() for cleaner separation of concerns
Continuation Handling: Remove ConfigureAwait(false) from PostCallback to ensure all continuations execute on the custom context
API Consistency: Add ConfigureAwait(false) to RunSync method to maintain consistent async patterns
Code Clarity: Add comments explaining the context behavior and why ConfigureAwait is not used in PostCallback
RunSync should not call ConfigureAwait(false) from within the anonymous function that is created. The anonymous function is ultimately executed within the context of the CustomSynchronizationContext and continuations should occur on that context, not on the thread pool.
Regardless of the above changes, attempting to call the async methods of the HttpClient from the CustomSynchronizationContext still results in a deadlock. I have updated #2371 with a solution that no longer uses the CustomSynchronizationContext as it does not seem capable of solving the deadlock issues of HttpClient.
Description
Deliverables