[Bug] Interactive auth callback hangs forever when an idle connection reaches AuthCodeReceiver first
Maintainers usually reply within 7 days
Nobody has claimed this yet.
- #971 by @Thanatos9404 — closed without merging
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- authentication, backend
Research direction
Start by reading AuthCodeReceiver and its use of HttpServer; the issue identifies synchronous request handling and a connection accepted before the OAuth POST as the suspected path. Reproduce the flow with an idle connection reaching the listener first, then check that the real OAuth POST is processed and az login completes. The issue does not name a test file.
Written by the indexing model from the issue text.
Description
Describe the bug
When I run az login in my VS code terminal (using the VS Code SSH extension to connect to my Linux VM), it either succeeds, or it hangs forever after I log in via the browser until I close the browser and cancel the command. If I retry a couple of times, sometimes 1 succeeds. (Sometimes I spam 10x and it'll work once - fairly annoying).
To Reproduce
Steps to reproduce the behavior:
- Use the VS Code SSH extension to connect to a Linux VM
- az login on the VM (not with device code, this is using interactive auth via the browser)
- Login using the browser
- Login either works fine, or hangs forever
Expected behavior
The normal flow, looking at the code-
- az cli asks MSAL to perform interactive auth
- MSAL creates a temp HTTP server on a port and registers a redirect URI
- az cli opens the entra login auth page in the browser
- after auth, entra should be returning an HTML form that the browser POSTs to the redirect URI
- VS Code remote SSH forwards the local connection to that port on the Linux machine
- MSAL reads the auth code from the POST and does the token exchange
TLDR: the local browser should POST to the localhost port on the VS code tunnel, then to the MSAL HTTP server, before returning the auth code to az cli.
What you see instead
- MSAL was listening on the redirect port, ex. 39397
- An idle TCP connection arrives from a different ephemeral source port (this could really be from anything, but I'm guessing it has to do with the VS code remote SSH behavior - I think it shouldn't matter, though).
- MSAL accepted that connection
- It was an empty connection - no requests arrive
- The real OAuth POST arrives from a different port
- The real OAuth POST sits in the server's request queue forever
Accepted idle connection:
127.0.0.1:39397 <-> 127.0.0.1:40890
Recv-Q: 0
Queued real callback:
127.0.0.1:39397 <-> 127.0.0.1:40902
Recv-Q: 3026
The MSAL Python version you are using
- Azure CLI: 2.89.0
- MSAL Python: 1.36.0
- Also present in MSAL Python 1.37.0 source
- Python: Azure CLI bundled Python 3.14
- OS: Ubuntu 22.04
- Client: VS Code Remote SSH with a Windows browser
Additional context
I think this is a race condition and if the OAuth connection reaches the listening port first, everything works fine.
A few things I noticed:
- AuthCodeReceiver is using HttpServer, which I think is singled threaded. I can't find the GitHub link, but looking at the handler in Python source it looks like we process the request synchronously and don't accept another connection until the handler is done
self._server.timeout = timeoutin AuthCodeReceiver is for accepting new requests, but this hang should be happening after the initial accept - we're just waiting for the request bytes
- Dominant language
- Python
- Stars
- 971
- Forks
- 223
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AzureAD/microsoft-authentication-library-for-python
-
needs attention untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
AzureAD/microsoft-authentication-library-for-python#997 ·
Maintainers usually reply within 7 days
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
AzureAD/microsoft-authentication-library-for-python#980 ·
Maintainers usually reply within 7 days
-
[Bug] User Realm Discovery drops the authority's port, so username/password sign-in fails on non-443 authoritiesPossibly taken @THEtheChad claimed this 20 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
AzureAD/microsoft-authentication-library-for-python#989 ·
Maintainers usually reply within 7 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
AzureAD/microsoft-authentication-library-for-python#984 ·
Maintainers usually reply within 7 days
-
[Bug] Support library-agnostic HTTP clients for Service Fabric managed identityPossibly taken @4gust claimed this 20 days ago. OpenAzureSDK bug P1
Difficulty 4/5 3-5 days Newbie friendliness 48/100
AzureAD/microsoft-authentication-library-for-python#965 · 1 comment · 1 assignee ·
Maintainers usually reply within 7 days
All issues in AzureAD/microsoft-authentication-library-for-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
bad-antics/lateralus-lang#1623 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
fossguild/thelifesnake#82 ·
Maintainers usually reply within 1 day
-
Unfitted DialectClassifier crashes with a confusing ValueError: raise a clear "not fitted" errorOpengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
omarelshamy25x/shamy-arabic-nlp#111 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pietbarber/Manage2Soar#1189 ·
Maintainers usually reply within 1 day
-
BUG: write_netcdf fails on Tutorial 3 BEM output with pandas CategoricalDtype DOF coordinatesPossibly taken @dtgaebe claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
sandialabs/WecOptTool#467 ·