Skip to content

ClientTimeout values of 0 don't disable timeouts #5527

Closed
@rmoe

Description

🐞 Describe the bug
ClientTimeout values of 0 and None are treated differently. The docs here state:

All fields are floats, None or 0 disables a particular timeout check

and versions 3.6.3 and earlier do work this way. After #5091 this behavior was changed.

💡 To Reproduce
This simple example illustrates the issue:

timeout = aiohttp.ClientTimeout(
    total=90,
    connect=0,
    sock_connect=0,
    sock_read=0
)

async with aiohttp.ClientSession(timeout=timeout) as session:
    print(await session.get("https://google.com"))

With v3.6.3:

ryan@debian:~$ python -m pip show aiohttp
Name: aiohttp
Version: 3.6.3

ryan@debian:~$ python test.py
<ClientResponse(https://www.google.com/) [200 OK]>

With v3.7.4:

ryan@debian:~$ python -m pip show aiohttp
Name: aiohttp
Version: 3.7.4

ryan@debian:~$ python test.py
Traceback (most recent call last):
  File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/aiohttp/connector.py", line 999, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/async_timeout/__init__.py", line 45, in __exit__
    self._do_exit(exc_type)
  File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

...

File "/home/ryan/.virtualenvs/aio-test/lib/python3.9/site-packages/aiohttp/client.py", line 524, in _request
    raise ServerTimeoutError(
aiohttp.client_exceptions.ServerTimeoutError: Connection timeout to host https://google.com

This timeout happens immediately.

With 3.7.4 if I change the timeout values from 0 to None it works correctly.

ryan@debian:~$ python -m pip show aiohttp
Name: aiohttp
Version: 3.7.4

ryan@debian:~$ python test.py
<ClientResponse(https://www.google.com/) [200 OK]>

💡 Expected behavior
Timeouts with values of 0 should be ignored (or the docs updated to say 0 doesn't disable the timeouts).

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions