From 7fc07debf81783bc2fdb0ee2391c69f1b478dc85 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 27 Feb 2017 11:35:19 -0500 Subject: [PATCH] Set a 60 second timeout on web Web connections were defaulting to infinite timeout. If a problem happened in the midst of a connection, a request could hang things indefinitely. Add a 60 second timeout to purge these situations. Change-Id: Ica05e2bfb9242ccc564e39c8631d8bf7e3f230a5 --- pyghmi/util/webclient.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 507ddba5..5696407e 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -35,6 +35,8 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): def __init__(self, host, port=None, key_file=None, cert_file=None, ca_certs=None, strict=None, verifycallback=None, **kwargs): + if 'timeout' not in kwargs: + kwargs['timeout'] = 60 httplib.HTTPConnection.__init__(self, host, port, strict, **kwargs) self.cert_reqs = ssl.CERT_NONE # verification will be done ssh style.. self._certverify = verifycallback @@ -45,7 +47,7 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): self.stdheaders[key] = value def connect(self): - plainsock = socket.create_connection((self.host, self.port)) + plainsock = socket.create_connection((self.host, self.port), 60) self.sock = ssl.wrap_socket(plainsock, cert_reqs=self.cert_reqs) # txtcert = self.sock.getpeercert() # currently not possible bincert = self.sock.getpeercert(binary_form=True)