From 0e65c5ab4e4c92cd14a43b9b65048b8b57d36ec9 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 4de9728541..c367d1084c 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):