self._reject_connection = True
self._stream_reader_wr = None
- def _untrack_reader(self):
- self._stream_reader_wr = None
-
@property
def _stream_reader(self):
if self._stream_reader_wr is None:
return self._transport.can_write_eof()
def close(self):
- # a reader can be garbage collected
- # after connection closing
- self._protocol._untrack_reader()
self._transport.close()
def is_closing(self):
info.append(f'stderr={self.stderr!r}')
return '<{}>'.format(' '.join(info))
- def _untrack_reader(self):
- # StreamWriter.close() expects the protocol
- # to have this method defined.
- pass
-
def connection_made(self, transport):
self._transport = transport
client_writer.write(data)
await client_writer.drain()
client_writer.close()
+ await client_writer.wait_closed()
def start(self):
sock = socket.socket()
# read it back
msgback = await reader.readline()
writer.close()
+ await writer.wait_closed()
return msgback
messages = []
client_writer.write(data)
await client_writer.drain()
client_writer.close()
+ await client_writer.wait_closed()
def start(self):
self.server = self.loop.run_until_complete(
# read it back
msgback = await reader.readline()
writer.close()
+ await writer.wait_closed()
return msgback
messages = []
self.assertEqual(messages, [])
+ def test_eof_feed_when_closing_writer(self):
+ # See http://bugs.python.org/issue35065
+ messages = []
+ self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
+
+ with test_utils.run_test_server() as httpd:
+ rd, wr = self.loop.run_until_complete(
+ asyncio.open_connection(*httpd.address,
+ loop=self.loop))
+
+ f = wr.aclose()
+ self.loop.run_until_complete(f)
+ assert rd.at_eof()
+ f = rd.read()
+ data = self.loop.run_until_complete(f)
+ assert data == b''
+
+ self.assertEqual(messages, [])
+
if __name__ == '__main__':
unittest.main()