From e46dda7e760fac25f5cb2c2af016e373b827ceae Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Sun, 13 Mar 2016 14:41:08 -0700 Subject: [PATCH] fix infinite recursion when destroying sockets By having a `getattr` implementation that proxies to the `sock` attribute, there is a risk of infinite recursion when the socket attribute is absent. After closing the socket and destroying it, the recursion can be prevented by setting the attribute to `None`. --- gunicorn/sock.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gunicorn/sock.py b/gunicorn/sock.py index 4de972854..c367d1084 100644 --- a/gunicorn/sock.py +++ b/gunicorn/sock.py @@ -53,11 +53,15 @@ def bind(self, sock): sock.bind(self.cfg_addr) def close(self): + if self.sock is None: + return + try: self.sock.close() except socket.error as e: self.log.info("Error while closing socket %s", str(e)) - del self.sock + + self.sock = None class TCPSocket(BaseSocket):