summaryrefslogtreecommitdiff
diff options
authorOlivier Gayot <olivier.gayot@canonical.com>2022-04-22 18:25:22 +0200
committergit-ubuntu importer <ubuntu-devel-discuss@lists.ubuntu.com>2022-05-10 20:58:33 +0000
commit8d91b30f9a66d184b02fc106559375f6c802e401 (patch)
treeb6268245fb97a5cacf019ec175882af4f799a8f8
parent316fedbd7752fc442957157acfcc8e0381237b8c (diff)
Imported using git-ubuntu import.
Notes
Notes: * Backport upstream patch to fix resolver tasks not awaited on cancellation (LP: #1969817)
-rw-r--r--debian/changelog7
-rw-r--r--debian/control3
-rw-r--r--debian/patches/0003-Fix-resolver-task-not-always-awaited.patch121
-rw-r--r--debian/patches/series1
4 files changed, 131 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog
index 438e9fb..f528d0f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+python-aiohttp (3.6.2-1ubuntu1) focal; urgency=medium
+
+ * Backport upstream patch to fix resolver tasks not awaited on cancellation
+ (LP: #1969817)
+
+ -- Olivier Gayot <olivier.gayot@canonical.com> Thu, 22 Apr 2022 18:25:22 +0200
+
python-aiohttp (3.6.2-1build1) focal; urgency=medium
* No-change rebuild to drop python3.7.
diff --git a/debian/control b/debian/control
index fcc353a..3eb1139 100644
--- a/debian/control
+++ b/debian/control
@@ -1,7 +1,8 @@
Source: python-aiohttp
Section: python
Priority: optional
-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Uploaders: Tianon Gravi <admwiggin@gmail.com>,
Paul Tagliamonte <paultag@debian.org>,
Piotr Ożarowski <piotr@debian.org>,
diff --git a/debian/patches/0003-Fix-resolver-task-not-always-awaited.patch b/debian/patches/0003-Fix-resolver-task-not-always-awaited.patch
new file mode 100644
index 0000000..3c2c12d
--- /dev/null
+++ b/debian/patches/0003-Fix-resolver-task-not-always-awaited.patch
@@ -0,0 +1,121 @@
+Description: Fix resolver task is not awaited when connector is cancelled
+Author: Serhii Charykov <laammaar@gmail.com>
+Origin: upstream, https://github.com/aio-libs/aiohttp/commit/9b918a3fc6d87a97c02d7f96ff81a6b3502ba693
+Bug: https://github.com/aio-libs/aiohttp/issues/4330
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-aiohttp/+bug/1969817
+Last-Update: 2022-04-21
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+Index: b/aiohttp/connector.py
+===================================================================
+--- a/aiohttp/connector.py
++++ b/aiohttp/connector.py
+@@ -953,18 +953,27 @@
+ sslcontext = self._get_ssl_context(req)
+ fingerprint = self._get_fingerprint(req)
+
++ host = req.url.raw_host
++ assert host is not None
++ port = req.port
++ assert port is not None
++ host_resolved = asyncio.ensure_future(self._resolve_host(
++ host,
++ port,
++ traces=traces), loop=self._loop)
+ try:
+ # Cancelling this lookup should not cancel the underlying lookup
+ # or else the cancel event will get broadcast to all the waiters
+ # across all connections.
+- host = req.url.raw_host
+- assert host is not None
+- port = req.port
+- assert port is not None
+- hosts = await asyncio.shield(self._resolve_host(
+- host,
+- port,
+- traces=traces), loop=self._loop)
++ hosts = await asyncio.shield(host_resolved)
++ except asyncio.CancelledError:
++ def drop_exception(
++ fut: 'asyncio.Future[List[Dict[str, Any]]]'
++ ) -> None:
++ with suppress(Exception, asyncio.CancelledError):
++ fut.result()
++ host_resolved.add_done_callback(drop_exception)
++ raise
+ except OSError as exc:
+ # in case of proxy it is not ClientProxyConnectionError
+ # it is problem of resolving proxy ip itself
+Index: b/tests/test_connector.py
+===================================================================
+--- a/tests/test_connector.py
++++ b/tests/test_connector.py
+@@ -755,6 +755,50 @@
+ await f
+
+
++@pytest.fixture
++def dns_response_error(loop):
++ async def coro():
++ # simulates a network operation
++ await asyncio.sleep(0)
++ raise socket.gaierror(-3, 'Temporary failure in name resolution')
++ return coro
++
++
++async def test_tcp_connector_cancel_dns_error_captured(
++ loop,
++ dns_response_error) -> None:
++
++ exception_handler_called = False
++
++ def exception_handler(loop, context):
++ nonlocal exception_handler_called
++ exception_handler_called = True
++
++ loop.set_exception_handler(mock.Mock(side_effect=exception_handler))
++
++ with mock.patch('aiohttp.connector.DefaultResolver') as m_resolver:
++ req = ClientRequest(
++ method='GET',
++ url=URL('http://temporary-failure:80'),
++ loop=loop
++ )
++ conn = aiohttp.TCPConnector(
++ use_dns_cache=False,
++ )
++ m_resolver().resolve.return_value = dns_response_error()
++ f = loop.create_task(
++ conn._create_direct_connection(req, [], ClientTimeout(0))
++ )
++
++ await asyncio.sleep(0)
++ f.cancel()
++ with pytest.raises(asyncio.CancelledError):
++ await f
++
++ gc.collect()
++ assert exception_handler_called is False
++
++
+ async def test_tcp_connector_dns_tracing(loop, dns_response) -> None:
+ session = mock.Mock()
+ trace_config_ctx = mock.Mock()
+Index: b/CONTRIBUTORS.txt
+===================================================================
+--- a/CONTRIBUTORS.txt
++++ b/CONTRIBUTORS.txt
+@@ -212,6 +212,7 @@
+ SeongSoo Cho
+ Sergey Ninua
+ Sergey Skripnick
++Serhii Charykov
+ Serhii Kostel
+ Simon Kennedy
+ Sin-Woo Bang
+Index: b/CHANGES/4795.bugfix
+===================================================================
+--- /dev/null
++++ b/CHANGES/4795.bugfix
+@@ -0,0 +1 @@
++Fix resolver task is not awaited when connector is cancelled
diff --git a/debian/patches/series b/debian/patches/series
index 4af15c4..8cd6cda 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
0002-Use-local-install-of-jquery.patch
0002-Add-shebang-to-examples.patch
+0003-Fix-resolver-task-not-always-awaited.patch