Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Core} Ignore psutil.AccessDenied in _get_parent_proc_name #19244

Merged
merged 4 commits into from
Aug 31, 2021

Conversation

jiasli
Copy link
Member

@jiasli jiasli commented Aug 17, 2021

Description

Fix #19193

When parent or grandparent process path is too long, psutil used by Azure CLI fails:

Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 223, in invoke
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/init.py", line 132, in show_version
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/style.py", line 131, in print_styled_text
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/style.py", line 131, in
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/style.py", line 158, in format_styled_text
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 1266, in get_parent_proc_name
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 1254, in _get_parent_proc_name
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/init.py", line 617, in name
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_pswindows.py", line 750, in name
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_pswindows.py", line 681, in wrapper
psutil.AccessDenied: psutil.AccessDenied (pid=1080)

The psutil issue is tracked at giampaolo/psutil#1980

Change

This PR ignores psutil.AccessDenied so that get_parent_proc_name won't fail.

Testing Guide

Use legacy Windows PowerShell terminal powershell.exe to launch Azure CLI with a very long path:

D:\cli\py38-32\Scripts\pythonloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong.exe -m azure.cli --version --debug
  • After this PR, get_parent_proc_name won't fail as we ignore psutil.AccessDenied
  • In addition, if CLI is run in a no-TTY environment, like ADO, color will be disabled automatically and get_parent_proc_name won't be called at all.

@yonzhan
Copy link
Collaborator

yonzhan commented Aug 17, 2021

Core

@jiasli jiasli changed the title {Core} Ignore psutil.AccessDenied {Core} Ignore psutil.AccessDenied in _get_parent_proc_name Aug 17, 2021
@jiasli jiasli mentioned this pull request Aug 23, 2021
@jiasli jiasli merged commit 7c11970 into Azure:dev Aug 31, 2021
@jiasli jiasli deleted the psutil-access-denied branch August 31, 2021 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows 10: AZ cli 2.20.0+ fails psutil.AccessDenied when executed by process with path longer than 107 chars
4 participants