azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

CLI Hangs if auto upgrades are enabled, and command output is redirected

Open afscrome opened this issue 9 months ago • 2 comments

Describe the bug

If you have auto upgrade enabled (az config set auto-upgrade.enable=yes ), have an out of date Azure CLI and try to run the azure CLI in a context when standard input isn't avaialble, the azure CLI will hang indefinitely.

For example in PowerShell:

$foo = az version
az account get-access-token --only-show-errors | ConvertFrom-Json

Or from command prompt:

az account show | clip

Related command

I beleive this bug affects all commands. So far I've reproed on the following:

az version
az account show
az account get-access-token

Errors

No error message - the azure CLI just hangs indefinitely after outputting hte following

WARNING: New Azure CLI version available. Running 'az upgrade' to update automatically.
WARNING: This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
WARNING: Your current Azure CLI version is 2.58.0. Latest version available is 2.60.0.
WARNING: Please check the release notes first: https://docs.microsoft.com/cli/azure/release-notes-azure-cli

Issue script & Debug output

powershell

$foo = az account show --debug

output:

DEBUG: cli.knack.cli: Command arguments: ['account', 'show', '--debug']
DEBUG: cli.knack.cli: __init__ debug log:
Cannot enable color.
DEBUG: cli.knack.cli: Event: Cli.PreExecute []
DEBUG: cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x0000023CFFEEF880>, <function OutputProducer.on_global_arguments at 0x0000023C802C6020>, <function CLIQuery.on_global_arguments at 0x0000023C802F3BA0>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
DEBUG: cli.azure.cli.core: Modules found from index for 'account': ['azure.cli.command_modules.profile', 'azure.cli.command_modules.resource']
DEBUG: cli.azure.cli.core: Loading command modules:
DEBUG: cli.azure.cli.core: Name                  Load Time    Groups  Commands
DEBUG: cli.azure.cli.core: profile                   0.008         2         8
DEBUG: cli.azure.cli.core: resource                  0.177        51       228
DEBUG: cli.azure.cli.core: Total (2)                 0.185        53       236
DEBUG: cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next']
DEBUG: cli.azure.cli.core: Loading extensions:
DEBUG: cli.azure.cli.core: Name                  Load Time    Groups  Commands  Directory
DEBUG: cli.azure.cli.core: Total (0)                 0.000         0         0
DEBUG: cli.azure.cli.core: Loaded 52 groups, 236 commands.
DEBUG: cli.azure.cli.core: Found a match in the command table.
DEBUG: cli.azure.cli.core: Raw command  : account show
DEBUG: cli.azure.cli.core: Command table: account show
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x0000023C83186D40>]
DEBUG: cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\alexanderc\.azure\commands\2024-05-02.14-40-36.account_show.10108.log'.
INFO: az_command_data_logger: command args: account show --debug
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x0000023C831F1300>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x0000023C831F13A0>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x0000023C831F14E0>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
DEBUG: cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x0000023C802C60C0>, <function CLIQuery.handle_query_parameter at 0x0000023C802F3C40>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x0000023C831F1440>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x0000023C831CA3E0>, <function _x509_from_base64_to_hex_transform at 0x0000023C831CA480>]
DEBUG: cli.knack.cli: Event: CommandInvoker.OnFilterResult []
DEBUG: cli.knack.cli: Event: Cli.SuccessfulExecute []
DEBUG: cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x0000023C83186FC0>]
INFO: az_command_data_logger: exit code: 0
INFO: cli.__main__: Command ran in 0.700 seconds (init: 0.500, invoke: 0.200)
WARNING: cli.__main__: New Azure CLI version available. Running 'az upgrade' to update automatically.
WARNING: This command is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
WARNING: Your current Azure CLI version is 2.58.0. Latest version available is 2.60.0.
WARNING: Please check the release notes first: https://docs.microsoft.com/cli/azure/release-notes-azure-cli

(And at this point, the terminal hangs and the azure cli doesn't exit until ctrl+c is pressed)

Expected behavior

When no standard input is availble, the upgrade command shouldn't hang waiting for user input

Environment Summary

azure-cli 2.58.0 *

core 2.58.0 * telemetry 1.1.0

Extensions: resource-graph 2.1.0

Dependencies: msal 1.26.0 azure-mgmt-resource 23.1.0b2

Additional context

When auto upgrade is enabled and prompting is required, the auto upgrade should not happen if standard input isn't available as the prompt will never be resolved.

afscrome avatar May 02 '24 13:05 afscrome

Hi @afscrome,

2.58.0 is not the latest Azure CLI(2.60.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

Thank you for opening this issue, we will look into it.

yonzhan avatar May 02 '24 13:05 yonzhan

If az config set auto-upgrade.prompt=no is not set, CLI will wait for your confirmation: Do you want to continue? (Y/n)

bebound avatar May 06 '24 02:05 bebound