Mutex fail: Access to the path 'Global\AzurePowerShellConfigInit' is denied. #25701
Labels
bug
This issue requires a change to an existing behavior in the product in order to be resolved.
customer-reported
needs-triage
This is a new issue that needs to be triaged to the appropriate team.
Description
On our Azure DevOps build-agents we regularly get the following error:
This issue seems to be cause by the fact that we run two Azure DevOps agents on one server (VM). When both agents run some Az Powershell concurrently, this issue can manifest itself. We know this multiple DevOps agent per VM setup isn't best-practice and should be avoided. However, it is what it is and our admins so far haven't changed this setup. This same issue has also been reported on StackOverflow by someone else: https://stackoverflow.com/questions/78807247/azurepowershell5-fails-to-initialize-access-to-the-path-global-azurepowershe
Anyway, regardless of the DevOps scenario, I think this is a broader issue regarding running Az concurrently. I delved into the issue. This is the error call stack:
The issue seems to be caused by a failed creation of a global Mutex in the
AzureSessionInitializer
class:https://github.com/Azure/azure-powershell/blob/611a694abe53f830c1bd5f661266f8c06f2f0b58/src/Accounts/Authentication/AzureSessionInitializer.cs#L326C13-L326C86
I've done some Googling and it appears a race condition can happen between the creation of the global Mutex and setting its accompanying ACL. This should be prevented by providing security settings in the Mutex constructor (some discussion here and here).
In the latest versions of .NET it seems the Mutex constructor that accepts security settings has been removed. Instead there's now the MutexAcl class that should be used for this.
I hope this all makes sense and that Microsoft can provide a fix for this. Of course we will also try to get our DevOps agent setup fixed. But as I said before, I think this really is an issue that could manifest itself in other scenarios too.
Issue script & Debug output
Environment data
Module versions
Error output
The text was updated successfully, but these errors were encountered: