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

Use wait_closed with asyncio, with socket unwrapping workaround. #84

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 13 additions & 1 deletion httpcore/_backends/asyncio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from ssl import SSLContext
from ssl import SSLContext, SSLWantReadError
from typing import Optional

from .._exceptions import (
Expand Down Expand Up @@ -158,6 +158,18 @@ async def aclose(self) -> None:
async with self.write_lock:
with map_exceptions({OSError: CloseError}):
self.stream_writer.close()
# Unwrap the SSL socket, ignoring want-read errors.
# Refs https://bugs.python.org/issue39758
try:
ssl_object = self.stream_writer.get_extra_info("ssl_object")
if ssl_object is not None:
ssl_object.unwrap()
except SSLWantReadError:
pass
else:
if hasattr(self.stream_writer, "wait_closed"):
# Python 3.7+
await self.stream_writer.wait_closed() # type: ignore

def is_connection_dropped(self) -> bool:
# Counter-intuitively, what we really want to know here is whether the socket is
Expand Down