Skip to content

python.async_resource_cleanup

Stability High

Detects async resources not properly cleaned up.

Leaked async resources:

  • Connection leaks — Clients/sockets not closed
  • Resource exhaustion — File descriptors run out
  • Memory leaks — Objects never garbage collected
# ❌ Before (resource not cleaned up)
async def fetch_data():
client = httpx.AsyncClient()
response = await client.get(url)
return response.json()
# Client never closed!
# ✅ After (proper cleanup with async context manager)
async def fetch_data():
async with httpx.AsyncClient() as client:
response = await client.get(url)
return response.json()
# Client automatically closed
  • AsyncClient without async context manager
  • aiofiles.open without async with
  • Database connections not closed