Skip to content

[ASP.NET] Replace RestSharp with something that has better support for async code. #9511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ACIStymie opened this issue Jun 21, 2019 · 2 comments

Comments

@ACIStymie
Copy link

RestSharp does not behave well with the AspNetSynchronizationContext. Callbacks with in the code leaves the synchronization context. On reentry the context (among other housekeeping) drops Thread.CurrentPrincipal and sets it to HttpContext.Current.User. Which causes problems with projects that have different values for these principals. It is also less efficient to switch the context and will not perform as well in high performance projects. Even if you set UseSynchronizationContext to true for async code, the result is the same. Additionally, setting UseSynchronizationContext to true calls AspNetSynchronizationContext.Post, Which itself has re-entrant behavior. The re-entrant behavior in my experience continues up the chain of async calls every time the code continues after an await. So caching and resetting Thread.CurrentPrincipal after an awaited call only lasts till the end of the method.
For reference:
https://blog.stephencleary.com/2009/10/synchronizationcontext-properties.html

I do not have experience with other Synchronization Contexts but I would imagine they could have side effects as well.

An API client with a more current asynchronous implementation would be better. I started to look at Flurl which might be a candidate. https://flurl.dev/. But didn't see synchronous supported calls off hand.

It's beyond me at this point to attempt this sort of update. Hopefully someone else might be up to it.

@frantuma
Copy link
Member

frantuma commented Aug 1, 2019

see also #1889

@phil-warner
Copy link

I can confirm that RestClient.ExecuteTaskAsync(request) never returns, and because the packaged RestSharp client is 105.1.0 it's swallowing the errors, so we can't diagnose what's happening.

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

No branches or pull requests

3 participants