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`.
This commit is contained in:
Randall Leeds 2016-03-13 14:41:08 -07:00
parent e05941cec2
commit e46dda7e76

View File

@ -53,11 +53,15 @@ class BaseSocket(object):
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):