Skip to content
Myr

Merge pull request #40 from encode/graceful-behavior-for-unclosed-https-connections

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Graceful behavior for unclosed HTTPS connections

authored by Tom Christie · committed by GitHub · parents 93d7ba3, 6d162a0 · Browse files · 1 file+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+20 added−1 removed

  • other:+20 added−1 removed

1 file+20 added−1 removed

modified:httpcore/backends/default.py+20 added-1 removed
18 unmodified lines
1920OptionalTimeout = typing.Optional[TimeoutConfig]212223# Monky-patch for https://bugs.python.org/issue3670924#25# This prevents console errors when outstanding HTTPS connections26# still exist at the point of exiting.27#28# Clients which have been opened using a `with` block, or which have29# had `close()` closed, will not exhibit this issue in the first place.3031_write = asyncio.selector_events._SelectorSocketTransport.write3233def _fixed_write(self, exc):34 if not self._loop.is_closed():35 _write(self, exc)3637asyncio.selector_events._SelectorSocketTransport.write = _fixed_write383940class Reader(BaseReader):41 def __init__(42 self, stream_reader: asyncio.StreamReader, timeout: TimeoutConfig43 ) -> None:
30 unmodified lines
74 timeout = self.timeout7576 self.stream_writer.write(data)77 try:61 data = await asyncio.wait_for( # type: ignore78 await asyncio.wait_for( # type: ignore79 self.stream_writer.drain(), timeout.write_timeout80 )81 except asyncio.TimeoutError:82 raise WriteTimeout()
54 unmodified lines
137 ident = ssl_object.selected_alpn_protocol()138 if ident is None:139 ident = ssl_object.selected_npn_protocol()140141 stream_writer.transport.set_write_buffer_limits(high=0, low=0)142143 reader = Reader(stream_reader=stream_reader, timeout=timeout)144 writer = Writer(stream_writer=stream_writer, timeout=timeout)145 protocol = Protocol.HTTP_2 if ident == "h2" else Protocol.HTTP_11146
1 unmodified line