-
Notifications
You must be signed in to change notification settings - Fork 599
Re-evaluate sync vs async extension points in AuthenticationHandler #76
Comments
The first option is probably the best one! 👍 You should also make |
Here's a breakdown of the various code paths:
All sync and async code paths are currently in use internally or exposed to application code so there are no overloads that we can just eliminate. The problem can be broken down into two parts; the request (Authenticate) and the response (Grant/Challenge). For the request code path the infrastructure has no dependencies on the sync APIs but they are exposed to application code. We'd have to evaluate the app and Identity usage scenarios to see if we could eliminate the sync code path. For the response the only sync dependency is OnSendingHeaders. Making OSH async would eliminate the need for the sync overloads. OSH could be fully async except when triggered by sync response stream APIs (Write/Flush), and even then the server would have some discretion (e.g. Helios does write-behind buffering, so it could fire OSH async even on sync code paths). |
In Katana 3, Concerning Identity, they are only using the async version: |
Yup, identity is fully async, I'm not a huge fan of having sync and async overloads either, +1 for eliminating sync if possible |
@Tratcher is this something you think we can/should do? It definitely would make things a lot cleaner |
Note: We will have to convince @lodejard but I think we should try if you agree that this is the 'right' thing to do... |
@HaoK I tried working through it once without much success. It's hard to get around the OnSendingHeaders code path. Take a look and let me know if you agree/disagree. |
Sounds like this is DOA since we can't get any traction...closing |
Any idea why this suggestion was not easy to implement? |
OnSendingHeaders was the big blocker. It needs to be sync (due to Stream.Write), but we wanted everything else to be async, so we're left with dual code paths. |
And calling |
bit of a noob, here. but, I'm messing with auth middleware. on googling i came to here so thought id post. On my handler, it is asking for AuthenticateCore as it is abstract, I already have async method, so slightly unsure what to do with it right now. Right, now, some other things are not compiling, so i cant test but once I will let you know happens. I expect I am doing something completely wrong, and I expect this is totally unrelated to the onheader thing, but thought just say, that asyc/sync. thing can get little confusing. |
AuthenticateCore is required, AuthenticateCoreAsync is an optional overload if you need to do anything async. See https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNet.Authentication/AuthenticationHandler.cs#L242 |
@Tratcher no remark concerning my last question? 😄 |
We don't want to have Wait's hidden in the server code, we want them to be a conscious choice at the middleware layer. |
Citing kestrel code isn't going to help your argument, we already know it's broken :-). |
Well, I don't have access to aspnet/WebListener or aspnet/Helios, so... 😄 The best argument I have is that currently, everybody is paying the price of a |
AuthenticatoinHandler has several abstract/virtial APIs where it has both a sync and async overload, and the developer can choose to implement one or the other. It's very common for the sync implementation to call the async method and block. The base handler calls the sync and async overloads in different circumstances, such as sync calls from OnSendingHeaders.
Theory 1: Get rid of the sync calls, make OnSendingHeaders async.
Theory 2: Get rid of any async calls that are only called from OnSendingHeaders. Make sure there is only one overload of each extension point, be it sync or async.
The text was updated successfully, but these errors were encountered: