Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore protocol exceptions after it is closed #6321

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/4526.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore protocol exceptions after it is closed.
5 changes: 4 additions & 1 deletion aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)
from .client_proto import ResponseHandler
from .client_reqrep import SSL_ALLOWED_TYPES, ClientRequest, Fingerprint
from .helpers import _SENTINEL, ceil_timeout, is_ip_address, sentinel
from .helpers import _SENTINEL, ceil_timeout, is_ip_address, sentinel, set_result
from .http import RESPONSES
from .locks import EventResultOrError
from .resolver import DefaultResolver
Expand Down Expand Up @@ -628,6 +628,9 @@ def _release(
if should_close or protocol.should_close:
transport = protocol.transport
protocol.close()
# TODO: Remove once fixed: https://bugs.python.org/issue39951
# See PR #6321
set_result(protocol.closed, None)

if key.is_ssl and not self._cleanup_closed_disabled:
self._cleanup_closed_transports.append(transport)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ async def test_release_close(key: Any) -> None:
assert proto.close.called


async def test_release_proto_closed_future(loop: Any, key: Any):
conn = aiohttp.BaseConnector()
protocol = mock.Mock(should_close=True, closed=loop.create_future())
conn._release(key, protocol)
# See PR #6321
assert protocol.closed.result() is None


async def test__drop_acquire_per_host1(loop: Any) -> None:
conn = aiohttp.BaseConnector()
conn._drop_acquired_per_host(123, 456)
Expand Down