Skip to content

fix(qobuz): close session when login() raises to avoid unclosed connector warnings#1005

Open
berettavexee wants to merge 1 commit into
nathom:devfrom
berettavexee:fix/qobuz-unclosed-session
Open

fix(qobuz): close session when login() raises to avoid unclosed connector warnings#1005
berettavexee wants to merge 1 commit into
nathom:devfrom
berettavexee:fix/qobuz-unclosed-session

Conversation

@berettavexee

Copy link
Copy Markdown

Problem

When QobuzClient.login() raises an exception (e.g. AuthenticationError on HTTP 401, MissingCredentialsError, InvalidAppIdError, IneligibleError, or any network error), the aiohttp.ClientSession created at the top of the method is never closed.

This produces the following warnings in the log:

ERROR asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x...>
ERROR asyncio: Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler ...>, 7133.06...)])']
connector: <aiohttp.connector.TCPConnector object at 0x...>

Fix

Wrap the body of login() in a try/except Exception block that closes the session before re-raising. If login succeeds the session stays open as before; if it fails the connector is cleaned up immediately.

self.session = await self.get_session(...)
try:
    # ... all login logic ...
    self.logged_in = True
except Exception:
    await self.session.close()
    raise

Notes

  • No behaviour change on the happy path
  • The docstring (which was placed after self.session = ..., making it unreachable by Python) has been moved to the correct position at the top of the method

…ctor warnings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant