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

az login hangs after selecting account #10578

Closed
sloscialo opened this issue Sep 19, 2019 · 9 comments · Fixed by #10955
Closed

az login hangs after selecting account #10578

sloscialo opened this issue Sep 19, 2019 · 9 comments · Fixed by #10955
Assignees
Labels
Account az login/account

Comments

@sloscialo
Copy link

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az login

Errors:
The command does launches a browser and allows me to select an account. After selecting an account, the browser just spins and the shell just waits.

I've left it running for 5 minutes before closing the browser or hitting Ctrl-C.

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • az login

Expected Behavior

I expect the command to launch a browser and allow me to select an account to log in with, then login me in.

Environment Summary

Windows-10-10.0.18362-SP0
Python 3.6.6
Shell: powershell.exe

azure-cli 2.0.73

Additional Context

What's strange is that if I use the --debug parameter, it works with no problems.

@qwordy qwordy added the Account az login/account label Sep 20, 2019
@jiasli
Copy link
Member

jiasli commented Sep 20, 2019

Azure CLI opens port 8400 to listen to returned auth code. The hang is usually caused by blocked 8400 port. You may use psping to test if port 8400 can be reached: https://docs.microsoft.com/en-us/sysinternals/downloads/psping

psping -t 127.0.0.1:8400

If the device can't open 8400, you may use az login --use-device-code.

@sloscialo
Copy link
Author

The port doesn't seem to be the problem.

@jiasli
Copy link
Member

jiasli commented Oct 15, 2019

When CLI is logining in, can psping connect?

@sloscialo
Copy link
Author

I get the following whether the CLI is logging in (when not logging in, it's all just refusals).

PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility
Copyright (C) 2012-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

TCP connect to 127.0.0.1:8400:
Infinite iterations (warmup 1) ping test:
Connecting to 127.0.0.1:8400 (warmup): from 127.0.0.1:43173: 0.16ms
Connecting to 127.0.0.1:8400: from 127.0.0.1:43175: 0.11ms
Connecting to 127.0.0.1:8400: from 127.0.0.1:43177: 0.10ms
Connecting to 127.0.0.1:8400: from 127.0.0.1:43178: 0.12ms
Connecting to 127.0.0.1:8400: from 0.0.0.0:43180:
The remote computer refused the network connection.
Connecting to 127.0.0.1:8400: from 0.0.0.0:43184:
The remote computer refused the network connection.
Connecting to 127.0.0.1:8400: from 0.0.0.0:43187:
<snip lots more of these refusals />

@jiasli
Copy link
Member

jiasli commented Oct 22, 2019

Possibly related to Python's HTTPServer using allow_reuse_address = 1: https://github.com/python/cpython/blob/3.7/Lib/http/server.py#L133

Per Git Blame, this change is introduced in python/cpython@18865de. This has a side-effect on Windows: https://stackoverflow.com/a/14388707/2199657

Windows only knows the SO_REUSEADDR option, there is no SO_REUSEPORT. Setting SO_REUSEADDR on a socket in Windows behaves like setting SO_REUSEPORT and SO_REUSEADDR on a socket in BSD, with one exception: A socket with SO_REUSEADDR can always bind to exactly the same source address and port as an already bound socket, even if the other socket did not have this option set when it was bound.

Thus HTTPServer is not able to detect 8400 is in-use. We will fix this logic on Windows.

@sloscialo
Copy link
Author

Note that this problem is intermittent and I cannot replicate the exact circumstances that cause az login to just hang after the account selection.

Also, not sure if this is related, but when developing in VS2019 that uses Azure KeyVault for developer secrets, I have to run az login multiple times throughout the day...sometimes in between debugging runs (that is, not idle for very long).

@jiasli
Copy link
Member

jiasli commented Oct 24, 2019

In this PR, if port 8400 is occupied, CLI will now print a warning. Let's see if this update exposes anything. You may copy the changed file from the PR to the installation folder for a quick test.

@welersonlisboa
Copy link

solved here - #26180

@jiasli
Copy link
Member

jiasli commented Apr 20, 2023

@welersonlisboa, this issue is not relevant to #26180.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Account az login/account
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants