bug .azure folder mounted from WSL2 creates lock errors with many requests
See original GitHub issueDescribe the bug
When running terraform inside WSL2 together with a .azure folder mounted inside windows seems like we get file lock issues.
│ Error: getting authenticated object ID: Error parsing json result from the Azure CLI: Error waiting for the Azure CLI: exit status 1: ERROR: The command failed with an unexpected error. Here is the traceback:
│ ERROR: [Errno 2] No such file or directory
│ Traceback (most recent call last):
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 352, in handler
│ client = self.client_factory(self.cli_ctx) if self.client_factory else None
│ TypeError: get_graph_client_signed_in_users() missing 1 required positional argument: '_'
│
│ During handling of the above exception, another exception occurred:
│
│ Traceback (most recent call last):
│ File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 231, in invoke
│ cmd_result = self.invocation.execute(args)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 657, in execute
│ raise ex
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
│ results.append(self._run_job(expanded_arg, cmd_copy))
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 712, in _run_job
│ return cmd_copy.exception_handler(ex)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/role/commands.py", line 69, in graph_err_handler
│ raise ex
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 691, in _run_job
│ result = cmd_copy(params)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in __call__
│ return self.handler(*args, **kwargs)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/command_operation.py", line 354, in handler
│ client = self.client_factory(self.cli_ctx, command_args) if self.client_factory else None
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/role/commands.py", line 89, in get_graph_client_signed_in_users
│ return _graph_client_factory(cli_ctx).signed_in_user
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/role/_client_factory.py", line 25, in _graph_client_factory
│ resource=cli_ctx.cloud.endpoints.active_directory_graph_resource_id)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 335, in get_login_credentials
│ credential = self._create_credential(account, client_id=client_id)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 588, in _create_credential
│ return identity.get_user_credential(username_or_sp_id)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/auth/identity.py", line 182, in get_user_credential
│ return UserCredential(self.client_id, username, **self._msal_app_kwargs)
│ File "/opt/az/lib/python3.6/site-packages/azure/cli/core/auth/msal_authentication.py", line 41, in __init__
│ accounts = self.get_accounts(username)
│ File "/opt/az/lib/python3.6/site-packages/msal/application.py", line 872, in get_accounts
│ accounts = self._find_msal_accounts(environment=self.authority.instance)
│ File "/opt/az/lib/python3.6/site-packages/msal/application.py", line 912, in _find_msal_accounts
│ query={"environment": environment})
│ File "/opt/az/lib/python3.6/site-packages/msal_extensions/token_cache.py", line 53, in find
│ with CrossPlatLock(self._lock_location):
│ File "/opt/az/lib/python3.6/site-packages/msal_extensions/cache_lock.py", line 29, in __enter__
│ file_handle = self._lock.__enter__()
│ File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 199, in __enter__
│ return self.acquire()
│ File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 161, in acquire
│ fh = self._prepare_fh(fh)
│ File "/opt/az/lib/python3.6/site-packages/portalocker/utils.py", line 194, in _prepare_fh
│ fh.truncate(0)
│ FileNotFoundError: [Errno 2] No such file or directory
│ To open an issue, please run: 'az feedback'
│
│ with provider["registry.terraform.io/hashicorp/azuread"],
│ on main.tf line 19, in provider "azuread":
│ 19: provider "azuread" {}
The terraform module that we are using uses both azurerm and azuread. I think the switch between the modules is to quick and WSL2 don’t have enough time to release the azure cli json file that it uses.
To Reproduce Run lots of azure cli requests inside of WSL2 with a .azure folder mounted to windows. I don’t have a reliable way of creating this issue.
Expected behavior To not get the error.
Have some try logic that makes sure that this doesn’t happen. Probably a simple retry to get the lock file will solve the problem to give WSL2/windows time to release the file lock. But I’m just guessing now.
Environment summary
Linux-5.10.60.1-microsoft-standard-WSL2-x86_64-with-debian-buster-sid, Ubuntu 18.04.5 LTS Python 3.6.10 Installer: DEB
azure-cli 2.32.0
Additional context
I have tried to explain this issue in our external docs: https://github.com/XenitAB/xenitab.github.io/pull/80
*Workaround
Found a workaround which is to not to store .azure inside windows. Assuming that pwd isn’t a windows folder.
export AZURE_CONFIG_DIR=$(pwd)/.azure
# Store Azure CLI configuration here
[ -d $(pwd)/.azure ] || mkdir $(pwd)/.azure
# login to azure agaiin
az login
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
This is weird, as the file content is indeed wrong. Here is my L53:
Could you also check
If everything is correct, could you follow https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt and reinstall?
We do see corrupted/outdated files after upgrading with MSI on Windows (https://github.com/Azure/azure-cli/issues/20990), but upgrading with
apt-get
resulting in outdated file is something we saw for the first time. 🤔I tried to decompile the
pyc
file on my WSL and the content is also correct: