Open
Conversation
added 2 commits
March 16, 2026 16:31
…ext when it is run. This simplifies the RunSync method and clarifies the context in which the PostCallback is ran.
Author
|
@dotnet-policy-service agree company="The Davey Tree Expert Company" |
Contributor
Review Summary by QodoRefactor CustomSynchronizationContext to prevent deadlocks
WalkthroughsDescription• Refactored CustomSynchronizationContext to manage context setup internally • Removed ConfigureAwait(false) from task execution to ensure continuations stay on custom context • Added ConfigureAwait(false) to RunSync<T> method's await call • Simplified RunSync method by moving context management into CustomSynchronizationContext.Run() Diagramflowchart LR
A["RunSync calls<br/>CustomSynchronizationContext"] -->|"simplified"| B["CustomSynchronizationContext.Run<br/>manages context"]
B -->|"sets context"| C["SynchronizationContext<br/>set to custom"]
C -->|"executes"| D["PostCallback<br/>without ConfigureAwait"]
D -->|"ensures continuations<br/>stay on context"| E["Prevents deadlocks<br/>and thread pool jumps"]
File Changes1. src/RestSharp/AsyncHelpers.cs
|
Contributor
Code Review by Qodo
1.
|
The anonymous method in the RunSync call does not capture the current context until it is executed. Because it is called from within the CustomSynchronizationContext, it will always capture the CustomSynchhronizationContext and not the caller's context. This reverts commit ec15969.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
ConfigureAwait(false)to await call in RunSync method.ConfigureAwait(false)method call on the task executed from the CustomSynchronizationContext to ensure continuations occur on the custom context, not the thread pool.Purpose
These changes should prevent deadlocks from calling async methods and ensure that continuations happen synchronously on the CustomSynchronizationContext instead of the thread pool.
History
The CustomSychronizationContext implementation was originally pulled from https://github.com/rebus-org/Rebus/blob/27b212a2380d55edc16a0036dfefd8e6b3ad9c2c/Rebus/Bus/Advanced/RebusAsyncHelpers.cs
Their correct implementation does not call
ConfigureAwait(false)on the task executed from within the CustomSynchronizationContext to ensure any continuations are queued on the CustomSynchronnizationContext, not the thread pool.