You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure CLI(az-cli)间歇性卡顿缓慢问题求助

Azure CLI 间歇性卡顿问题排查

问题现象

  • 执行速度不稳定:部分命令可在10秒内完成,但简单查询(如版本检查)偶尔耗时80秒以上
  • 触发场景:长时间使用后,或打开多个终端窗口且至少两个窗口用过Azure CLI时出现

示例命令及耗时输出

执行命令:

az --version --debug

80秒后输出:

az --version --debug
cli.knack.log: File logging enabled - writing logs to 'C:\Users\localuser\.azure\logs'.
cli.knack.cli: Command arguments: ['--version', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
urllib3.connectionpool: Starting new HTTPS connection (1): raw.githubusercontent.com:443
urllib3.connectionpool: https://raw.githubusercontent.com:443 "HEAD / HTTP/1.1" 301 0
cli.azure.cli.core.util: Connectivity check: 4.057321899999806 sec
urllib3.connectionpool: Starting new HTTPS connection (1): raw.githubusercontent.com:443
urllib3.connectionpool: https://raw.githubusercontent.com:443 "GET /Azure/azure-cli/main/src/azure-cli-core/setup.py HTTP/1.1" 200 1350
urllib3.connectionpool: Starting new HTTPS connection (1): raw.githubusercontent.com:443
urllib3.connectionpool: https://raw.githubusercontent.com:443 "GET /Azure/azure-cli/main/src/azure-cli-telemetry/setup.py HTTP/1.1" 200 680
azure-cli                         2.65.0

core                              2.65.0
telemetry                          1.1.0

Extensions:
account                            0.2.5
automation                       1.0.0b1
azure-devops                       1.0.1
init                               0.1.0
next                               0.1.3

Dependencies:
msal                              1.31.0
azure-mgmt-resource               23.1.1

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

Python (Windows) 3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x000002CAA0E1C360>]
cli.__main__: Command ran in 84.876 seconds (init: 0.211, invoke: 84.665)

后续更新(2024-10-25)

  • 重装Azure CLI后问题暂时消失,但后续复发
  • 插拔网线可临时恢复速度,但无永久解决方案

问题解答

耗时是否正常?

绝对不正常。az --version属于本地轻量命令,即使包含版本检查,正常耗时也应在5秒以内,80秒的执行时间明显超出合理范围。

可能的原因分析

  • 网络连接异常:CLI需要连接raw.githubusercontent.com做版本检查,若本地网络到该域名的连接存在间歇性丢包、路由延迟或DNS解析卡顿,会导致请求超时等待;插拔网线临时恢复,说明网络链路或本地网络栈存在异常(如TCP连接池耗尽、网卡缓存异常)。
  • 多终端会话资源冲突:多个终端同时使用Azure CLI时,可能出现本地缓存(token缓存、扩展缓存)的读写锁竞争,导致命令阻塞等待锁释放;长时间使用后,缓存文件碎片化或锁资源未正常释放,也会引发卡顿。
  • CLI扩展或依赖问题:已安装的扩展可能存在兼容性问题,或扩展的后台更新检查占用资源;Python依赖库的缓存或版本冲突,导致初始化时加载缓慢。
  • Windows系统资源限制:长时间运行后,系统进程占用过高内存/CPU,导致Azure CLI的Python进程无法获得足够资源;终端窗口的控制台子系统存在资源泄漏,多窗口叠加后影响性能。

临时缓解建议

  • 禁用CLI自动版本检查:设置环境变量AZURECLI_DISABLE_CONNECTION_CHECK=1,避免每次命令触发网络请求。
  • 清理Azure CLI缓存:删除C:\Users\localuser\.azure目录下的cache、logs文件夹,重启终端。
  • 减少同时运行的Azure CLI会话数量,避免多窗口资源竞争。
  • 重置本地网络栈:执行ipconfig /flushdns、netsh winsock reset命令,替代插拔网线的操作。

内容的提问来源于stack exchange,提问作者Daniel M.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 00:58:28