swagger-api / swagger-api/swagger-codegen
[ASP.NET] Replace RestSharp with something that has better support for async code.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by identifying the ASP.NET client templates and how they use RestSharp, then evaluate Flurl and its synchronous and asynchronous support. Done means replacing the client dependency without the reported synchronization-context and principal-handling problems.
Written by the indexing model from the issue text.
Assessment
- Domain
- api
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100