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

Fix deadlock in AzureCliCredential and other process based TokenCredential implementations #16247

Closed

Conversation

likemike91
Copy link

This PR fixes an issue where large tokens (e.g. due to being member of a lot of groups in AAD) caused all TokenCredential implementations which use the ProcessRunner to fail with a Timeout due to a deadlock when reading the StandardOut stream.

@ghost ghost added Azure.Identity customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 24, 2020
@ghost
Copy link

ghost commented Oct 24, 2020

Thank you for your contribution likemike91! We will review the pull request and get back to you soon.

@ghost
Copy link

ghost commented Oct 24, 2020

CLA assistant check
All CLA requirements met.

@likemike91
Copy link
Author

likemike91 commented Oct 24, 2020

This fixes #14691 and #14207

@likemike91 likemike91 marked this pull request as ready for review October 24, 2020 21:38
@likemike91 likemike91 changed the title Fix deadlock when using azure cli and token is large Fix deadlock with large token from AzureCliCredential and other process based TokenCredential implementations Oct 24, 2020
@likemike91 likemike91 changed the title Fix deadlock with large token from AzureCliCredential and other process based TokenCredential implementations Fix deadlock in AzureCliCredential and other process based TokenCredential implementations Oct 24, 2020
@jsquire
Copy link
Member

jsquire commented Oct 26, 2020

Hi @likemike91. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. Tagging and routing to the team members best able to provide feedback.

@jsquire jsquire added Client This issue points to a problem in the data-plane of the library. Community Contribution Community members are working on the issue and removed customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Oct 26, 2020
@jsquire
Copy link
Member

jsquire commented Oct 29, 2020

@schaabs: Would you please be so kind as to offer your feedback?

@schaabs
Copy link
Member

schaabs commented Oct 29, 2020

@likemike91 Thanks for your contribution helping us address this issue which is impacting lots of users! Apologies on the delay getting you feedback. I have a couple of high level comments on this approach. First, the current implementation of ProcessRunner is non-blocking, but using AutoResetEvent for synchronization introduces blocking calls. Did you consider using TaskCompletionSource rather than AutoResetEvent to signal when the output is complete so that it can be awaited rather than blocking? Secondly, this change complicates the IProcess abstraction quite a bit, and requires implementing events to mock. Since, in the end we, read the process output and error to a string, perhaps we could simplify the abstraction by just exposing the stdout and stderr content as string properties? Again, thank you for the contribution, and please let me know if you have any questions or thoughts on the approaches I outlined.

@likemike91
Copy link
Author

likemike91 commented Nov 1, 2020

@schaabs Thank you for your feedback on my implementation. I now switched over the implementation to TaskCompletionSource to be non-blocking respectively awaitable (90bf469). With the last commit (e76cce2) I tried to overcome some race conditions where the process.Exited event is received before the last process.OutputDataReceived or process.ErrorDataReceived event is received.
Regarding your second suggestion to move the event handling stuff into the ProcessWrapper itself I can't think of a simple solution without totally rewriting the whole ProcessRunner/IProcess stuff since I also have to handle those race conditions mentioned before as well. Maybe I'm thinking too complicated right now but if so maybe you can point me into the right direction? 🙈

PS: I added two cleanup commits 🙈 (0bab3ed, a05f4b8)

@AlexanderSher
Copy link
Contributor

AlexanderSher commented Nov 2, 2020

@likemike91, I really am sorry that I've left these issues unresolved before going on a long leave. Thank you very much for your contribution.
@schaabs Sorry, I've completely forgotten about buffer overflow when I wrote ProcessRunner. Unfortunately, the only way we can read asynchronously from Process is by using OutputDataReceived and ErrorDataReceived events. I've created a PR that addresses this issue and also handles the case when Process.Start returns false.

@likemike91
Copy link
Author

@AlexanderSher Okay thank you for your reply. Then I'll assume I can Close/Remove my PR?

@likemike91 likemike91 closed this Nov 9, 2020
@likemike91
Copy link
Author

Closed due to #16499

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. Community Contribution Community members are working on the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants