restsharp / restsharp/RestSharp

Fix deadlocks in async-to-sync bridge by properly managing synchronization context

Open
#2,372 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
9.8k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

Description

  • 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating RunSync and CustomSynchronizationContext, then compare their context setup, teardown, and PostCallback behavior with the proven Rebus implementation pattern. The work is done when context ownership is moved into CustomSynchronizationContext.Run(), continuations remain on the custom context, RunSync uses ConfigureAwait(false), and the context behavior is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.