Skip to content

Exception trying to create a TLS connection with ClientTimeout(total=0) #11859

@mtdcr

Description

@mtdcr

Describe the bug

aiohttp passes timeout.total to start_tls(), causing an exception if the value of total is zero.

aiohttp/aiohttp/connector.py

Lines 1320 to 1337 in 8b919d3

# ssl_shutdown_timeout is only available in Python 3.11+
if sys.version_info >= (3, 11) and self._ssl_shutdown_timeout:
tls_transport = await self._loop.start_tls(
underlying_transport,
tls_proto,
sslcontext,
server_hostname=req.server_hostname or req.url.raw_host,
ssl_handshake_timeout=timeout.total,
ssl_shutdown_timeout=self._ssl_shutdown_timeout,
)
else:
tls_transport = await self._loop.start_tls(
underlying_transport,
tls_proto,
sslcontext,
server_hostname=req.server_hostname or req.url.raw_host,
ssl_handshake_timeout=timeout.total,
)

Due to the contradictory meaning for zero (no timeout / invalid value), I think this special case should get handled inside aiohttp, for example by passing timeout.total or None, causing asyncio to use the default value of 60 seconds instead of throwing an exception.

To Reproduce

Create client connection to TLS service with ClientTimeout(total=0), like Music Assistant does for Deezer.

Expected behavior

No unhandled exception.

Logs/tracebacks

music-assistant[813603]:   File "/usr/local/lib/python3.13/asyncio/sslproto.py", line 284, in __init__
music-assistant[813603]:     raise ValueError(
music-assistant[813603]:         f"ssl_handshake_timeout should be a positive number, "
music-assistant[813603]:         f"got {ssl_handshake_timeout}")
music-assistant[813603]: ValueError: ssl_handshake_timeout should be a positive number, got 0

Python Version

3.13.6

aiohttp Version

3.12.15

multidict Version

$ python -m pip show multidict

propcache Version

$ python -m pip show propcache

yarl Version

$ python -m pip show yarl

OS

Music Assistant Docker image

Related component

Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions