Skip to content

Fix issue Connect-AzAccount fail in multi-threaded execution #12041

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

Merged
merged 4 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Fixed an issue that may cause `Connect-AzAccount` to fail in multi-threaded execution [#11201]

## Version 1.8.1
* Fixed an issue that may cause Az to skip logs in Azure Automation or PowerShell jobs [#11492]
Expand Down
14 changes: 10 additions & 4 deletions src/Accounts/Authentication/AzureSessionInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,24 @@ public override SourceLevels AuthenticationTraceSourceLevel
/// <summary>
/// Adal Logger for Adal 3.x +
/// </summary>
public AdalLogger AdalLogger { get; private set; }
public AdalLogger AdalLogger { get; private set; }

/// <summary>
/// Write messages to the existing trace listeners when log messages occur
/// </summary>
/// <param name="message"></param>
private void WriteToTraceListeners(string message)
{
foreach (var listener in AuthenticationTraceListeners)
for (var i = 0; i < AuthenticationTraceListeners.Count; ++i) // don't use foreach, enumerator is not thread safe
{
var trace = listener as TraceListener;
trace.WriteLine(message);
try
{
AuthenticationTraceListeners[i].WriteLine(message);
}
catch
{
// ignroe any exception
}
}
}
#endif
Expand Down