simple_httpclient and servers that close the connection after sending the
response.
if not self.socket:
return
if events & self.io_loop.ERROR:
- self.close()
+ # We may have queued up a user callback in _handle_read or
+ # _handle_write, so don't close the IOStream until those
+ # callbacks have had a chance to run.
+ self.io_loop.add_callback(self.close)
return
state = self.io_loop.ERROR
if self.reading():
self.wait()
self.assertFalse(self.connect_called)
+ def test_connection_closed(self):
+ # When a server sends a response and then closes the connection,
+ # the client must be allowed to read the data before the IOStream
+ # closes itself. Epoll reports closed connections with a separate
+ # EPOLLRDHUP event delivered at the same time as the read event,
+ # while kqueue reports them as a second read/write event with an EOF
+ # flag.
+ response = self.fetch("/", headers={"Connection": "close"})
+ response.rethrow()