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

Don't raise exceptions on graceless close cases #310

Merged
merged 1 commit into from
Apr 28, 2021
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
5 changes: 2 additions & 3 deletions httpcore/_backends/anyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from anyio.streams.tls import TLSAttribute, TLSStream

from .._exceptions import (
CloseError,
ConnectError,
ConnectTimeout,
ReadError,
Expand Down Expand Up @@ -101,8 +100,8 @@ async def aclose(self) -> None:
async with self.write_lock:
try:
await self.stream.aclose()
except BrokenResourceError as exc:
raise CloseError from exc
except BrokenResourceError:
pass

def is_readable(self) -> bool:
sock = self.stream.extra(SocketAttribute.raw_socket)
Expand Down
5 changes: 3 additions & 2 deletions httpcore/_backends/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from .. import _utils
from .._exceptions import (
CloseError,
ConnectError,
ConnectTimeout,
ReadError,
Expand Down Expand Up @@ -186,7 +185,7 @@ async def aclose(self) -> None:
is_ssl = self.stream_writer.get_extra_info("ssl_object") is not None

async with self.write_lock:
with map_exceptions({OSError: CloseError}):
try:
self.stream_writer.close()
if is_ssl:
# Give the connection a chance to write any data in the buffer,
Expand All @@ -196,6 +195,8 @@ async def aclose(self) -> None:
if hasattr(self.stream_writer, "wait_closed"):
# Python 3.7+ only.
await self.stream_writer.wait_closed() # type: ignore
except OSError:
pass

def is_readable(self) -> bool:
transport = self.stream_reader._transport # type: ignore
Expand Down
5 changes: 3 additions & 2 deletions httpcore/_backends/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Optional, Type

from .._exceptions import (
CloseError,
ConnectError,
ConnectTimeout,
ReadError,
Expand Down Expand Up @@ -74,8 +73,10 @@ def write(self, data: bytes, timeout: TimeoutDict) -> None:

def close(self) -> None:
with self.write_lock:
with map_exceptions({socket.error: CloseError}):
try:
self.sock.close()
except socket.error:
pass

def is_readable(self) -> bool:
return is_socket_readable(self.sock.fileno())
Expand Down
5 changes: 3 additions & 2 deletions httpcore/_backends/trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import trio

from .._exceptions import (
CloseError,
ConnectError,
ConnectTimeout,
ReadError,
Expand Down Expand Up @@ -79,8 +78,10 @@ async def write(self, data: bytes, timeout: TimeoutDict) -> None:

async def aclose(self) -> None:
async with self.write_lock:
with map_exceptions({trio.BrokenResourceError: CloseError}):
try:
await self.stream.aclose()
except trio.BrokenResourceError:
pass

def is_readable(self) -> bool:
# Adapted from: https://github.com/encode/httpx/pull/143#issuecomment-515202982
Expand Down