I have this method that gets the og:image
meta tag of html pages asynchronously, I'm using httpx to stream the response so that i can stop reading when i encounter the og:image
tag. My problem is that I'm getting a serious memory leak that crashes the whole app after 40+ requests. This is the code sample:
async def getImg(url):
og_line = None
async with httpx.AsyncClient() as client:
async with client.stream('GET', url) as response:
async for chunk in response.aiter_lines():
if "og:image" in chunk:
og_line = chunk
break
My question is am I doing something horrible here by breaking in an async for
and this is expected (if yes would love to know how i can do it differently), or this is unexpected behavior? Thanks.