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

Various fixes/improvements #756

Merged
merged 4 commits into from
Dec 7, 2023
Merged

Various fixes/improvements #756

merged 4 commits into from
Dec 7, 2023

Conversation

Avery-Dunn
Copy link
Collaborator

This PR handles a number of small issues from our backlog:

@@ -209,7 +209,7 @@ private AuthorizationResult getAuthorizationResultFromHttpListener() {
expirationTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 1;
}

while (result == null && !interactiveRequest.futureReference().get().isCancelled()) {
while (result == null && !interactiveRequest.futureReference().get().isDone()) {
Copy link
Member

Choose a reason for hiding this comment

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

Timeout in interactive flow is not something MSALs do and it's not something we ask app dev to do either. It can take a really long time to perform auth - e.g. I was just asked to MFA and then to change password.

But anyway, it looks like this is based on public API, so it's fine.

Copy link
Collaborator Author

@Avery-Dunn Avery-Dunn Dec 5, 2023

Choose a reason for hiding this comment

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

For interactive flow we have a timeout parameter that would cause this loop to end after a default 120 seconds:

This ended up being kind of a weird situation. In Java 8 there wasn't really a timeout option for ending a future (there was a timeout for waiting for the result), however in Java 9 they started introducing methods for completing the future after a timeout. Since we target Java 8 as a minimum but also want to support newer versions, this means

  • Java 8 customers need that httpPollingTimeoutInSeconds as a timeout to end the interactive flow
  • Java 9+ customers can use the newer timeout methods in Java's CompletableFuture API, and will be confused if MSAL doesn't follow those timeouts

@@ -209,7 +209,7 @@ private AuthorizationResult getAuthorizationResultFromHttpListener() {
expirationTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 1;
}

while (result == null && !interactiveRequest.futureReference().get().isCancelled()) {
while (result == null && !interactiveRequest.futureReference().get().isDone()) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment on what "isDone" is doing here? I think it returns true when cancel() is called, or when the future completes with success?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

isDone returns true when a future is cancelled (like the current behavior), plus when it completes normally or with an exception. In other words, isDone covers any situation where we can't return the auth result, and there's no point in continuing this loop.

By only checking isCancelled there were scenarios where thread spun off to complete futures could continue to pointlessly run (such as when the app developers sets a timeout in the future #741).

@Avery-Dunn Avery-Dunn merged commit 1d81ee5 into dev Dec 7, 2023
4 of 5 checks passed
@Avery-Dunn Avery-Dunn deleted the avdunn/various-enhancements branch March 11, 2024 20:32
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.

2 participants