lexiforest / curl_cffi

Python binding for curl-impersonate fork via cffi. A http client that can impersonate browser tls/ja3/http2 fingerprints.
https://curl-cffi.readthedocs.io/
MIT License
2.4k stars 258 forks source link

[BUG] AsyncCurl TimerHandle leaks #164

Closed chengjinluo closed 10 months ago

chengjinluo commented 11 months ago

Describe the bug AsyncCurl holds TimerHandle of call_later task invoked by libcurl's timer function and it is not released after the delay function is called.

To Reproduce

import asyncio
from curl_cffi.requests import AsyncSession

async def main():
    async with AsyncSession() as sess:
        for _ in range(3):
            print('before', len(sess.acurl._timers))
            try:
                await sess.get('http://httpstat.us/200?sleep=5000', timeout=1)
            except:
                pass
            print('after', len(sess.acurl._timers))

if __name__ == '__main__':
    asyncio.run(main())

Output

before 0
after 7
before 7
after 10
before 10
after 14

Expected behavior Saved TimerHandle should be released after the delay function is called.

Versions

Additional context It seems using a WeakSet instead of list for acurl._timers could solve this problem.

perklet commented 11 months ago

Thanks, this might be the same problem as #113, this is a perfect bug report.

perklet commented 10 months ago

It should've been fixed in 0.6.0b7, feel free to reopen if the leak is not resolved.

WendyDReid1901 commented 1 month ago

The leaks issue was still there,please help!

perklet commented 2 weeks ago

The leaks issue was still there,please help!

Can you elaborate on your observations? Thanks.