From 15329144224cd6f55a76050eeb58e54549d2662c Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 19 Jan 2013 17:05:32 -0500 Subject: [PATCH] Save the address family when an HTTPConnection is created. Previously, if a non-IP socket was closed prematurely, we would still try to reference stream.socket.family to decide what format self.address was in, resulting in an uncaught exception. Closes #656. --- tornado/httpserver.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 5a981cceb..1781589fd 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -171,6 +171,10 @@ class HTTPConnection(object): xheaders=False, protocol=None): self.stream = stream self.address = address + # Save the socket's address family now so we know how to + # interpret self.address even after the stream is closed + # and its socket attribute replaced with None. + self.address_family = stream.socket.family self.request_callback = request_callback self.no_keep_alive = no_keep_alive self.xheaders = xheaders @@ -259,7 +263,7 @@ class HTTPConnection(object): headers = httputil.HTTPHeaders.parse(data[eol:]) # HTTPRequest wants an IP, not a full socket address - if self.stream.socket.family in (socket.AF_INET, socket.AF_INET6): + if self.address_family in (socket.AF_INET, socket.AF_INET6): remote_ip = self.address[0] else: # Unix (or other) socket; fake the remote address -- 2.47.2