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

Add close method to app #371

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Add close method to app #371

wants to merge 1 commit into from

Conversation

HansWeltar
Copy link

Fixes Issue #370 Session/socket never closed, warnings shown

The msal application does not close it's resources like eg: self.http_client.
As a result a 'ResourceWarning unclosed <ssl.SSLSocket' is shown when the
app goes out of scope (when warnings are enabled)

This fix adds and explicit close method so developpers can cleanly close
the app if they so desire.

@HansWeltar
Copy link
Author

A better fix might be needed. A close() method does not help in case of __init__ errors.
For example when you provide a wrong tenant_id

try:
    app = msal.application.ConfidentialClientApplication(APPID, client_credential=SECRET, 
        authority="https://login.microsoftonline.com/" + FAULTY_TENANT)
except Exception:
    app.close() -> fails because app is not defined....

Fixes Issue AzureAD#370 Session/socket never closed, warnings shown

The msal application does not close its resources like eg: self.http_client.
As a result a 'ResourceWarning unclosed <ssl.SSLSocket' is shown when the
app goes out of scope (when warnings are enabled)

This fix adds and explicit close method so developers can cleanly close
the app if they so desire.
In __init__ we trap and close the exception explicitely as users cannot
call close when __init__ fails.
Finally we don't close the http_client if it's externally managed.
@ghost
Copy link

ghost commented Jun 21, 2021

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ HansWeltar sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

@HansWeltar
Copy link
Author

adressed

A better fix might be needed. A close() method does not help in case of init errors.
For example when you provide a wrong tenant_id

try:
    app = msal.application.ConfidentialClientApplication(APPID, client_credential=SECRET, 
        authority="https://login.microsoftonline.com/" + FAULTY_TENANT)
except Exception:
    app.close() -> fails because app is not defined....

@bgavrilMS
Copy link
Member

Seems like the original issue still exists? Is this PR valid?

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

Successfully merging this pull request may close these issues.

3 participants