AuthenticateAsync behavior doesn't seem awaitable

Oct 14, 2013 at 1:35 AM
Edited Oct 14, 2013 at 2:56 PM
I'm wiring in the external auth features to POP Forums, and specifically, the first line of this method is giving me trouble:

https://popforums.codeplex.com/SourceControl/latest#PopForums/ExternalLogin/ExternalAuthentication.cs

If I change:
var authResult = await authenticationManager.AuthenticateAsync(ExternalCookieName);
...to:
var authResult = authenticationManager.AuthenticateAsync(ExternalCookieName).Result;
I have no issue, and I get a result every time. Similarly, if I put a break point on the next line, it will never be null. However, the awaitable version tends to return null almost all of the time, as if it's a race condition. Does this feel like a bug? I thought I'd ask before submitting an issue.
Coordinator
Oct 14, 2013 at 4:21 PM
await Task and Task.Result should always return the same result regardless of the underlying implementation. The only difference is that .Result blocks the calling thread. That you're seeing a difference means your calling methods may not be correctly awaiting the Task returned from GetAuthenticationResult.

Where is GetAuthenticationResult called?

Also, where's your Startup code that sets up the external auth?
Oct 14, 2013 at 4:50 PM
GetAuth is called in the controller, in the LoginAndAssociate method:

https://popforums.codeplex.com/SourceControl/latest#PopForums/Controllers/AuthorizationController.cs

I can put a break point there after the call (on the null check) and have the same result. Without the breakpoint, it's often null, but if I stop there, I get the result every time.

The OWIN setup is here:

https://popforums.codeplex.com/SourceControl/latest#PopForums/Configuration/PopForumsOwinStartup.cs

I came to the same conclusion that you did. Hanging out there on a breakpoint shouldn't change the outcome. That's why I'm so lost for answers. :)
Coordinator
Oct 14, 2013 at 5:58 PM
VS2013? I know they added await compatible debugging. I wonder if it has un-expected UI side-effects?

It would be great if you could extract a repro app.