Skip to content

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

@qodo-free-for-open-source-projects

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions