microsoft-authentication-library-for-python icon indicating copy to clipboard operation
microsoft-authentication-library-for-python copied to clipboard

Add close method to app

Open HansWeltar opened this issue 3 years ago • 4 comments

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 avatar Jun 21 '21 09:06 HansWeltar

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....

HansWeltar avatar Jun 21 '21 14:06 HansWeltar

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.

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

ghost avatar Jun 21 '21 15:06 ghost

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....

HansWeltar avatar Jun 21 '21 15:06 HansWeltar

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

bgavrilMS avatar Oct 10 '23 10:10 bgavrilMS