Skip to content
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

undo blocking on token polling ops; add docs & comments #4675

Merged
merged 1 commit into from
Sep 21, 2020
Merged

Conversation

stevengum
Copy link
Member

Fixes #4673 in 4.10 branch (will not close issue)

Specific Changes

  • Change from Task.WaitAll() to Task.WhenAll() to not block background polling operations
    • This is spiritual a "reversion" of some code factoring in the 4.10.0 release
  • Add comments/documentation explaining what the code is doing to prevent future breaks
  • Fix minor typo

Testing

Manually tested these changes along with a fix for microsoft/BotFramework-WebChat#3439 and the workaround mentioned in #4674 with Direct Line ASE and Direct Line Speech. The OAuth flow works as expected.

Note: No magic-code OAuth flows are not supported outside of regular Direct Line with Enhanced Authentication.

// Run the poll operations in the background.
// On retrieving a token from the token service the TokenResolver creates an Activity to route the token to the bot to continue the conversation.
// If these Tasks are awaited and the user doesn't complete the login flow, the bot may timeout in sending its response to the channel which can cause the streaming connection to disconnect.
Task.WhenAll(pollTokenTasks.ToArray());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are at it, it would be great to spend a bit of time making sure that any errors or timeouts in these polling tasks, there is a way for developers to detect them. Since these are ran in the background, the output status code is likely not the best avenue. However we do have a logger instance available and the ability to detect timeouts and failures in these tasks. If that seems of value, seems we could do a couple of things. 1) Catch those timeout and error scenarios. Code like the following could be in place

Task.WhenAll(pollTokenTasks.ToArray()).ContinueWith((task) =>
{
    if (task.IsCanceled)
    {
        // handle timeout logging
    }
    else if (task.IsFaulted)
    {
        // handle error, exceptions can be found in task.Exception.
    }
});

Ideally, this would be accompained by tests for timeout and fault scenario but not sure off hand how much ability we have to inject / unit test that behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with surfacing failures to the developer and I think it's handled in the TokenResolver.PollForTokenAsync() helper (code). When I switched WaitAll() to WhenAll() I thought about adding the ContinueWith() logic from 4.9. However, in R10 the PollForTokenAsync() logic was updated so that all exceptions are caught, so I didn't think it was necessary to restore the ContinueWith()

However, I haven't tested this path in an E2E scenario, so I'm not sure if the code works according to design 🙁

@Virtual-Josh was the last person to update the tests for this class, can you confirm if we have unit test coverage for surfacing errors?


Regarding unit testing this class, we can stand up Moqs to send back responses for 401s, the number of 404s, 5xxs to test both the number of polling operations and non-happy paths

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on the ContinueWith, not needed because of the new try-catch.

Regarding testing, adding negative tests to this code area would be great. Not mandatory for this PR but something I'd love to see in R11 as part of our investment to make this more solid.

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

Successfully merging this pull request may close these issues.

3 participants