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

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

Closed
PetrPospisil opened this issue Aug 11, 2021 · 5 comments · Fixed by #19244
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request Installation
Milestone

Comments

@PetrPospisil
Copy link

PetrPospisil commented Aug 11, 2021

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug
The issue is in python distro you are using. "psutil" lib fails with error psutil.AccessDenied
Introduced in 2.20.0 when you started to use psutil lib. Tried multiple AZ CLI versions (2.20.0, ..., 2.27.0)

To Reproduce
1] Install AZ CLI
2] Start some random process that has path longer than 107 characters and remember its PID
3] Execure your distro python with script

import psutil
import os
print(psutil.Process(PID).name())

3] It fails with an error:
C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2>python C:\test\test.py
Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_common.py", line 447, in wrapper
AttributeError: _cache

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_pswindows.py", line 679, in wrapper
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_common.py", line 450, in wrapper
File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_pswindows.py", line 766, in exe
PermissionError: [WinError 24] The program issued a command but the command length is incorrect: '(originated from NtQuerySystemInformation)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\users\safetica\downloads\test.py", line 4, in
print(psutil.Process(7192).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=7192)

Expected behavior
I expect to succeed without an error.

Environment summary
OS Name: Microsoft Windows Server 2019 Datacenter
OS Version: 10.0.17763 N/A Build 17763
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Server
OS Build Type: Multiprocessor Free
Hotfix(s): 6 Hotfix(s) Installed.
[01]: KB5004332
[02]: KB4486153
[03]: KB4535680
[04]: KB4589208
[05]: KB5003711
[06]: KB5004244

Additional context
I tried manually other python distros (3.8.10, 3.9.6, ...) using psutil lib (python.exe -m pip install psutil) and no failure occured. So I suspect that your python distro is somehow broken.

@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Aug 11, 2021
@PetrPospisil
Copy link
Author

PetrPospisil commented Aug 11, 2021

Parent issue:
microsoft/azure-pipelines-tasks#15138

@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Aug 11, 2021
@yonzhan yonzhan removed the question The issue doesn't require a change to the product in order to be resolved. Most issues start as that label Aug 11, 2021
@yonzhan yonzhan added this to the Aug 2021 (2021-09-07) milestone Aug 11, 2021
@yonzhan
Copy link
Collaborator

yonzhan commented Aug 11, 2021

@jiasli for awareness

@PetrPospisil
Copy link
Author

I tracked the issue to psutil python lib 32b running under wow64 WIN10 64b causing this issue.

@jiasli
Copy link
Member

jiasli commented Aug 17, 2021

Thanks @PetrPospisil for the comprehensive analysis.

I can repro by launching a very long process like D:\loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\python-3.9.6-embed-amd64\python.exe, then repro it with Azure CLI's bundled 32-bit Python:

# test.py
import psutil
import os
print(psutil.Process(PID).name())
> & "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" D:\test.py
Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_common.py", line 447, in wrapper
AttributeError: _cache

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_pswindows.py", line 679, in wrapper
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_common.py", line 450, in wrapper
  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\psutil/_pswindows.py", line 766, in exe
PermissionError: [WinError 24] The program issued a command but the command length is incorrect: '(originated from NtQuerySystemInformation)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\test.py", line 3, in <module>
    print(psutil.Process(16152).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=16152)

64-bit Python shows no problem:

> C:\Users\<name>\AppData\Local\Programs\Python\Python39\python.exe D:\test.py
python.exe

We do have a plan to use 64-bit Python (#18766), but it has not yet been started.

For now, let me submit a PR to ignore psutil's errors to bypass giampaolo/psutil#1980.

@PetrPospisil
Copy link
Author

I submited PR to the PSUtil lib

giampaolo/psutil#1981

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request Installation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants