This project has moved and is read-only. For the latest updates, please go here.

AuthenticateAsync behavior doesn't seem awaitable

Oct 14, 2013 at 2:35 AM
Edited Oct 14, 2013 at 3: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:

If I change:
var authResult = await authenticationManager.AuthenticateAsync(ExternalCookieName);
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.
Oct 14, 2013 at 5: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 5:50 PM
GetAuth is called in the controller, in the LoginAndAssociate method:

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:

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. :)
Oct 14, 2013 at 6: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.