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

Bug: ResourceWarning: Unclosed <MemoryObjectReceiveStream> with AsyncTestClient and anyio>=4.4 #3834

Closed
1 of 4 tasks
gsakkis opened this issue Oct 19, 2024 · 2 comments · Fixed by #3836
Closed
1 of 4 tasks
Labels
Bug 🐛 This is something that is not working as expected

Comments

@gsakkis
Copy link
Contributor

gsakkis commented Oct 19, 2024

Description

I started running tests with -W error and one of the (intermittent) warnings turned to errors was Unclosed <MemoryObjectReceiveStream>. After lots of digging I managed to reduce it to the MCVE below:

  • The test_httpx_async_client passes with both anyio==4.3.0 and anyio==4.4.0
  • The test_litestar_async_client passes only with anyio==4.3.0 (and previous versions)

Related anyio change: agronholm/anyio#715

URL to code causing the issue

No response

MCVE

import httpx
from litestar import Litestar
from litestar.testing import AsyncTestClient


app = Litestar(route_handlers=[])


async def test_httpx_async_client():
    for _ in range(10):
        async with httpx.AsyncClient(transport=httpx.ASGITransport(app)):
            pass


async def test_litestar_async_client():
    for _ in range(10):
        async with AsyncTestClient(app=app):
            pass

Steps to reproduce

`python -W error -m pytest test_resourcewarning.py`

Screenshots

"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

No response

Litestar Version

2.12.1

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)
@gsakkis gsakkis added the Bug 🐛 This is something that is not working as expected label Oct 19, 2024
Copy link

This issue has been closed in #3836. The change will be included in upcoming releases.

Copy link

A fix for this issue has been released in v2.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant