From: Ben Darnell Date: Sun, 5 May 2013 14:18:13 +0000 (-0400) Subject: Catch and ignore EINVAL errors from setsockopt. X-Git-Tag: v3.1.0~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91fd578d4ed1065c3ba53377a37bc3343f582a37;p=thirdparty%2Ftornado.git Catch and ignore EINVAL errors from setsockopt. This seems to happen a lot in benchmark runs when sockets are closed after a request. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 7a5c380da..1dfe06a68 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -742,8 +742,15 @@ class IOStream(BaseIOStream): def set_nodelay(self, value): if (self.socket is not None and self.socket.family in (socket.AF_INET, socket.AF_INET6)): - self.socket.setsockopt(socket.IPPROTO_TCP, - socket.TCP_NODELAY, 1 if value else 0) + try: + self.socket.setsockopt(socket.IPPROTO_TCP, + socket.TCP_NODELAY, 1 if value else 0) + except socket.error as e: + # Sometimes setsockopt will fail if the socket is closed + # at the wrong time. This can happen with HTTPServer + # resetting the value to false between requests. + if e.errno != errno.EINVAL: + raise class SSLIOStream(IOStream):