Skip to content

Prevent OData Client sync query deadlock under UI SynchronizationContext - #3543

Draft
xuzhg with Copilot wants to merge 3 commits into
mainfrom
copilot/odata-client-issue-fix
Draft

Prevent OData Client sync query deadlock under UI SynchronizationContext#3543
xuzhg with Copilot wants to merge 3 commits into
mainfrom
copilot/odata-client-issue-fix

Conversation

Copilot AI commented May 26, 2026

Copy link
Copy Markdown

In WinForms/WPF, synchronous LINQ execution (Where(...).ToList()) could hang even when the server responded, while ExecuteAsync completed. The sync path was waiting on async work that could resume on a blocked UI SynchronizationContext.

  • Root cause

    • HttpClientRequestMessage sync response flow (GetResponse) could block while an internal async continuation attempted to marshal back to the current context.
  • Client runtime change

    • Updated HttpClientRequestMessage.SendInternalAsync to avoid context capture on HttpClient.SendAsync:
      • added .ConfigureAwait(false) to the await in the send path.
    • This keeps sync callers from deadlocking when invoked from non-pumping UI contexts.
  • Regression coverage

    • Added a focused test in HttpClientRequestMessageTests using a non-pumping SynchronizationContext to verify GetResponse() completes instead of hanging.
// before
return await _client.SendAsync(_requestMessage, HttpCompletionOption.ResponseHeadersRead, sendToken);

// after
return await _client.SendAsync(_requestMessage, HttpCompletionOption.ResponseHeadersRead, sendToken)
    .ConfigureAwait(false);

Copilot AI changed the title [WIP] Fix odata client not returning when using where on WinForms or WPF Prevent OData Client sync query deadlock under UI SynchronizationContext May 26, 2026
Copilot finished work on behalf of xuzhg May 26, 2026 21:13
Copilot AI requested a review from xuzhg May 26, 2026 21:13
@nielsNocore

Copy link
Copy Markdown
Contributor

was also fixed in: #3527 but ether PR would be nice to be merged. @xuzhg

@nielsNocore nielsNocore mentioned this pull request Jun 18, 2026
2 tasks
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.

odata client never return when use where on winform or wpf

3 participants