From 613e0e381a2860c8f027b4665a20a90768875ebd Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 12 Jan 2011 21:28:52 +0100 Subject: scgi.asynchronous catches more errors now This addresses a disputed denial of service condition described in http://bugs.python.org/issue6706. Note that wsgitools is not hit as hard as pyftplib. --- wsgitools/scgi/asynchronous.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/wsgitools/scgi/asynchronous.py b/wsgitools/scgi/asynchronous.py index ecc27fb..82dec02 100644 --- a/wsgitools/scgi/asynchronous.py +++ b/wsgitools/scgi/asynchronous.py @@ -9,6 +9,7 @@ try: import cStringIO as io except ImportError: import StringIO as io +import errno class SCGIConnection(asyncore.dispatcher): """SCGI connection class used by L{SCGIServer}.""" @@ -228,10 +229,16 @@ class SCGIServer(asyncore.dispatcher): def handle_accept(self): """asyncore interface""" - ret = self.accept() - if ret is not None: - conn, addr = ret - SCGIConnection(self, conn, addr, **self.conf) + try: + ret = self.accept() + except socket.error, err: + # See http://bugs.python.org/issue6706 + if err.args[0] not in (errno.ECONNABORTED, errno.EAGAIN): + raise + else: + if ret is not None: + conn, addr = ret + SCGIConnection(self, conn, addr, **self.conf) def run(self): """Runs the server. It will not return and you can invoke -- cgit v1.2.3