HTTPSPublicKeyRetriever caches asyncio event loop - pytest-asyncio issues

Open
#143 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start in atlassian_jwt_auth/contrib/aiohttp/key.py around the HTTPSPublicKeyRetriever session handling, then reproduce the failure with two pytest-asyncio tests using separate event loops. Determine how the cached _class_session can be invalidated without relying on the deprecated client.loop attribute; done means both tests complete without reusing a session tied to a closed loop.

Written by the indexing model from the issue text.

Description

Hey there. I'm using atlassian_jwt_auth in an ayncio context; specifically using pytest-asyncio for the event loop creation. By default this library creates a new event loop for each test. (This is my desired behavior.)

However when running two tests that both utilize the HTTPSPublicKeyRetriever, the second test fails because the cached HTTPSPublicKeyRetriever._class_session is used with a now-shutdown event loop.

I've gotten around this with a fixture like so:

@pytest.fixture(autouse=True)
async def clean_https_session():
    yield
    await HTTPSPublicKeyRetriever._class_session.close()
    HTTPSPublicKeyRetriever._class_session = None

However this feels sort of wacky. Ideally I'd like the library to detect this and invalidate the _class_session either when the loop is shut down or when the session is gotten.

Adding a conditional here of client.loop != self.loop fixes the issue, but client.loop is deprecated in aiohttp and actually has been removed in the newest master branch.

Dominant language
Python
Stars
26
Forks
19
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from atlassian/asap-authentication-python

All issues in atlassian/asap-authentication-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.