Closed ZentixUA closed 9 months ago
For streaming, the timeout is currently only a connection timeout and not a read timeout, as per https://github.com/yifeikong/curl_cffi/issues/156.
You can achieve a read timeout by setting this before you request:
session.curl.setopt(CurlOpt.LOW_SPEED_LIMIT, 1) # 1 byte per second
session.curl.setopt(CurlOpt.LOW_SPEED_TIME, math.ceil(20.0)) # timeout after 20 seconds of receiving <=1byte/s
session.acurl.setopt(CurlOpt.LOW_SPEED_LIMIT, 1)
TypeError: initializer for ctype 'void *' must be a cdata pointer, not int
acurl
is not a curl instance, asyncio session uses a pool of curl instances, you can do like this:
session = AsyncSession(...,
curl_options={
CurlOpt.LOW_SPEED_LIMIT: 1,
CurlOpt.LOW_SPEED_TIME: math.ceil(20.0)
}
)
Thank you. What about a break
in the middle of iterating content as in the example? In aiohttp, the Response closes immediately, for instance. But with curl_cffi, I'm waiting 20-30 seconds. :(
Sorry, libcurl does not allow us to close the connection early. You can break from the iteration loop, but the connection will be floating around anyway. If your request number is not very big, it might be acceptable to just let the connections be closed automatically.
For streaming, the timeout is currently only a connection timeout and not a read timeout, as per #156.
You can achieve a read timeout by setting this before you request:
session.curl.setopt(CurlOpt.LOW_SPEED_LIMIT, 1) # 1 byte per second session.curl.setopt(CurlOpt.LOW_SPEED_TIME, math.ceil(20.0)) # timeout after 20 seconds of receiving <=1byte/s
Change this to default since v0.6.0b9.
Describe the bug Some hosts have an issue where, during streaming,
timeout
seems to have no effect; closing the connection on certain sources can take 20 or even 30 seconds, even when no new data is coming through. Other sources can completely hang and even with a timeout setting of(30, 60 * 10)
, they remain open for hours without closing.To Reproduce
I can provide another example, but it is quite private so perker can contact me in Telegram :)
Expected behavior The connection closes immediately
Versions
pip freeze
dump:Additional context