Fix: Ctrl+C results in handle_request failure #405
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refine #404
Symptom
_AuthCodeReceiver
is used as a context manager:microsoft-authentication-library-for-python/msal/oauth2cli/oauth2.py
Line 636 in f97cb7c
When Ctrl+C is pressed, Python calls
microsoft-authentication-library-for-python/msal/oauth2cli/authcode.py
Lines 279 to 280 in f97cb7c
then
microsoft-authentication-library-for-python/msal/oauth2cli/authcode.py
Lines 272 to 274 in f97cb7c
This shuts down the server and causes
microsoft-authentication-library-for-python/msal/oauth2cli/authcode.py
Line 264 in f97cb7c
to return.
Because of the outer loop
microsoft-authentication-library-for-python/msal/oauth2cli/authcode.py
Line 261 in f97cb7c
,
microsoft-authentication-library-for-python/msal/oauth2cli/authcode.py
Line 264 in f97cb7c
is called again. However, as the server has been shut down, it fails with
Change
If a request is handled by
msal.oauth2cli.authcode._AuthCodeHandler.do_GET
,self.server.auth_response
will always be set. Later on, ifself._server.handle_request()
returns leaving an emptyself.server.auth_response
, that means the server is shutdown before any request is handled, so we break the loop.