]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Save the address family when an HTTPConnection is created.
authorBen Darnell <ben@bendarnell.com>
Sat, 19 Jan 2013 22:05:32 +0000 (17:05 -0500)
committerBen Darnell <ben@bendarnell.com>
Sat, 19 Jan 2013 22:05:32 +0000 (17:05 -0500)
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

index 5a981ccebd5ddfcf990f28c3ea1c90b6fe48302f..1781589fdcaee7c27b6b5370396b8060e652a4b5 100644 (file)
@@ -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