curl_cffi: curl_cffi hangs indefinitely when waiting for response (no timeout or exception after 8+ hours)

Describe the bug When using AsyncSession with curl_cffi, the program sometimes hangs indefinitely (observed after 8+ hours of running) while waiting for a response, without triggering the timeout or raising any exceptions. The expected 20-second timeout doesn’t seem to be enforced in these cases. To Reproduce

import asyncio
import datetime
import logging
from curl_cffi.requests import AsyncSession

async def main():
    client = AsyncSession(timeout=20)
    while True:
        try:
            response = await client.get(
                "https://example.com", 
                impersonate="chrome131"
            )
            print(response.json())
        except curl_cffi.requests.exceptions.Timeout:
            print("time out", datetime.datetime.now())
            logging.info("time out")
        except Exception as e:
            print("exception occurred:", str(e))
            logging.exception("exception occurred")
        await asyncio.sleep(2)

asyncio.run(main())

Expected behavior

  1. Timeout should always be enforced after 20 seconds
  2. Either receive response or get timeout/network exception
  3. Program should never hang indefinitely

Versions

  • OS: Windows 11
  • curl_cffi 0.11.1

Additional context replace https://example.com

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 19 (5 by maintainers)

Most upvoted comments

@lexiforest Yes, I’m using asyncio. I also deal with a lot of requests, and I can guarantee that there are no issues with version 0.10.0.

I can confirm that 0.10.0 is not getting stalled.

Updating to 0.12.0b1 still didnt help my use case either. It still kind of freezes. Happens after the session is being run for like 4-5 hours after which it will stall. Going to try 0.10.0 and report back my findings in a day.

Updating to 0.12.0b1 didn’t do it for me, asyncio.wait_for still saves the day

@therealpurplemana Thanks!

For anyone visiting this page, please provide your feedback, it’s very hard for me to reproduce on my side.

client = AsyncSession()
response = await asyncio.wait_for(client.get(url, headers=base_headers, impersonate="chrome131"), 30)

asyncio.wait_for is not working