Uncaught exception when connector is cancelled
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-aiohttp (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Focal |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[Impact]
* When cancelling a connector task, the associated resolver task (if not finished) is not cancelled and continues running.
Unfortunately, if the resolver task eventually raises an exception (e.g., socket.gaierror), the exception will go directly to the exception handler because none will be awaiting the task anymore.
This results in applications crashing with exceptions such as:
Task exception was never retrieved
future: <Task finished name='Task-3' coro=<TCPConnec
Traceback (most recent call last):
File "/usr/lib/
addrs = await \
File "/usr/lib/
infos = await self._loop.
File "/usr/lib/
return await self.run_
File "/usr/lib/
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/
for res in _socket.
socket.gaierror: [Errno -2] Name or service not known
* This aiohttp bug is the root cause of a crash in Subiquity: https:/
Currently, we build the Subiquity snap based on deb packages (including python3-aiohttp) from focal. We temporarily moved from python3-aiohttp to python3-requests in Subiquity to work around this crash.
* Other applications based on python3-aiohttp can be affected and crash despite the absence of other bug reports.
* The patch in the debdiff makes sure that resolver tasks end up being awaited when the associated connector tasks gets cancelled.
[Test Plan]
* The following chunk of code can be executed to reproduce the issue: https:/
* The bug is way easier to reproduce is there is some delay in the DNS resolution. One way to simulate some delay is to use a non-local DNS server and run:
# tc qdisc add dev eth0 root netem delay 200ms
where eth0 is the name of the interface used for DNS resolutions.
This can be reverted using:
# tc qdisc del dev eth0 root netem
* On python3-aiohttp 3.6 (focal), the exception handler wakes up with:
Task exception was never retrieved
future: <Task finished name='Task-3' coro=<TCPConnec
* When aiohttp is patched, nothing should happen.
* Manually testing the patched library against Subiquity to make sure it solves https:/
This was done on my end using this PPA: https:/
[Where problems could occur]
* Since the patch affects a python library, any application that depends on this library (aka. python3-aiohttp) on focal would be affected by the upload.
* In the unlikely event that this patch introduces a regression, applications that depend on python3-aiohttp (i.e., in focal/universe) can crash or raise exceptions.
* If any package in focal/main has python3-aiohttp as a Build-Depends, a regression could cause said package to FTBFS.
[Other Info]
* The debdiff brings a backport of an upstream patch that is present in aiohttp 3.7 and newer versions:
https:/
* Upstream bug report: https:/
Changed in python-aiohttp (Ubuntu): | |
status: | New → Incomplete |
description: | updated |
description: | updated |
Changed in python-aiohttp (Ubuntu): | |
status: | Incomplete → New |
Changed in python-aiohttp (Ubuntu): | |
status: | New → Confirmed |
tags: | added: fr-2268 |
description: | updated |
description: | updated |
description: | updated |
Adding debdiff