Azure / Azure/azure-cli

Memory leak and crash in git bash if `--destination-path` is pefixed with a `/` for ` az storage file upload-batch`

Open
#32,147 1 comment 0 reactions 2 assignees Claimed by @calvinhzy View on GitHub
act-codegen-extensibility-squad Auto-Assign Azure CLI Team customer-reported question Storage
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

When passing a path with a prefixed `/` to the `--source` flag In **git bash** (Used in Azure pipelines on windows agent) `az storage file upload-batch` stalls and consumes more and more ram until it runs out and crashes.

Screenshot from my machine after about 20 sek. of running:
Image

This is the command that makes it crash:
`az storage file upload-batch --destination "$FILE_SHARE_URL" --source '.\Add-AppDevPackage.resources'/ --destination-path "/some/path" --account-key "$ACCOUNT_KEY" --debug`

This one works as expected:
`az storage file upload-batch --destination "$FILE_SHARE_URL" --source '.\Add-AppDevPackage.resources'/ --destination-path "some/path" --account-key "$ACCOUNT_KEY" --debug`

The subtle difference being that the second one does not have a `/` prefixed to `some/path`. I noticed in the debug output that git bash expanded `/some/path` into `C:/Program Files/Git/some/path`. This is probably out of scope for this repo, however, an error message about the path being invalid should be put in place instead of increasing memory consumption until it crashes.

### Related command

az storage file upload-batch

### Errors

From pipeline without debug flag:
```
##[warning]Free memory is lower than 5%; Currently used: 95.90%
ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR:
Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 666, in execute
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_job
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/storage/__init__.py", line 357, in new_handler
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 703, in _run_job
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 336, in __call__
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 120, in handler
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/storage/operations/file.py", line 201, in storage_file_upload_batch
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/storage/operations/file.py", line 152, in _execute_in_parallel
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/storage/operations/file.py", line 152, in
File "concurrent\futures\_base.py", line 449, in result
File "concurrent\futures\_base.py", line 401, in __get_result
File "concurrent\futures\thread.py", line 59, in run
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/storage/operations/file.py", line 187, in _upload_action
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/storage/operations/file.py", line 441, in _make_directory_in_files_share
MemoryError
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
```

### Issue script & Debug output

`az storage file upload-batch --destination "$FILE_SHARE_URL" --source '.\Add-AppDevPackage.resources'/ --destination-path "/some/path" --account-key "$ACCOUNT_KEY" --debug`

```
cli.knack.cli: Command arguments: ['storage', 'file', 'upload-batch', '--destination', 'FILESHARE_URL', '--source', '.\\Add-AppDevPackage.resources/', '--destination-path', 'C:/Program Files/Git/some/path', '--account-key', 'KEY', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
Enable VT mode.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [, , ]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'storage': ['azure.cli.command_modules.storage']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name Load Time Groups Commands
cli.azure.cli.core: storage 0.884 60 275
cli.azure.cli.core: Total (1) 0.884 60 275
cli.azure.cli.core: Loaded 60 groups, 275 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command : storage file upload-batch
cli.azure.cli.core: Command table: storage file upload
cli.azure.cli.core: remaining : batch
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate []
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\Aron\.azure\commands\2025-09-19.19-39-52.storage_file_upload-batch.25672.log'.
az_command_data_logger: command args: storage file upload-batch --destination {} --source {} --destination-path {} --account-key {} --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [.add_subscription_parameter at 0x000001BFEE42E5C0>]
cli.azure.cli.core.profiles._shared: Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/profiles/_shared.py", line 454, in _get_attr
File "importlib\__init__.py", line 88, in import_module
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1310, in _find_and_load_unlocked
File "", line 488, in _call_with_frames_removed
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'azure.mgmt.storage.blob'

cli.azure.cli.core.profiles._shared: Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/profiles/_shared.py", line 454, in _get_attr
File "importlib\__init__.py", line 88, in import_module
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'azure.mgmt.storage.file'

cli.azure.cli.core.profiles._shared: Traceback (most recent call last):
File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/profiles/_shared.py", line 454, in _get_attr
File "importlib\__init__.py", line 88, in import_module
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1310, in _find_and_load_unlocked
File "", line 488, in _call_with_frames_removed
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'azure.mgmt.storage.file'

cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [.add_ids_arguments at 0x000001BFEE458900>, .add_cache_arguments at 0x000001BFEE458AE0>, .update_breaking_change_info at 0x000001BFEE458B80>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [, , .parse_ids_arguments at 0x000001BFEE4589A0>]
cli.azure.cli.command_modules.storage._validators: Try to get storage auth_mode value from environment variables or config file.
cli.azure.cli.command_modules.storage._validators: Try to get storage account value from environment variables or config file.
cli.azure.cli.command_modules.storage._validators: Try to get storage account_url value from environment variables or config file.
cli.azure.cli.command_modules.storage._validators: Try to get storage account value from environment variables or config file.
cli.azure.cli.command_modules.storage._validators: Try to get storage account_url value from environment variables or config file.
cli.azure.cli.command_modules.storage._validators: Try to get storage sas_token value from environment variables or config file.
```

### Expected behavior

An error message to appear about the path being invalid instead of increasing memory consumption until it crashes.

### Environment Summary

azure-cli 2.77.0

core 2.77.0
telemetry 1.1.0

Dependencies:
msal 1.34.0b1
azure-mgmt-resource 23.3.0

Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe'
Config directory 'C:\Users\Aron\.azure'
Extensions directory 'C:\Users\Aron\.azure\cliextensions'

Python (Windows) 3.13.7 (tags/v3.13.7:bcee1c3, Aug 14 2025, 14:15:11) [MSC v.1944 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.