[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] When we see a httplib.BadStatusLine, sleep 5 seconds and then retry. This



# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID d37644abe52d0d10d54ab55157677f8612e4778e
# Parent  95f84e37c90d573dd01cc29db5b81ffb5f86f84a
When we see a httplib.BadStatusLine, sleep 5 seconds and then retry.  This
happens when Xend crashes, so retrying once allows it to restart and recover.
If we see Xend crash twice, we give up, but throw a more polite exception than
the BadStatusLine splat that we got previously.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 95f84e37c90d -r d37644abe52d tools/python/xen/xend/XendProtocol.py
--- a/tools/python/xen/xend/XendProtocol.py     Tue Dec 13 18:06:03 2005
+++ b/tools/python/xen/xend/XendProtocol.py     Tue Dec 13 18:07:51 2005
@@ -13,10 +13,12 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #============================================================================
 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@xxxxxx>
+# Copyright (C) 2005 XenSource Ltd.
 #============================================================================
 
 import socket
 import httplib
+import time
 import types
 
 from encode import *
@@ -165,23 +167,37 @@
         @param method: http method: POST or GET
         @param args:   request arguments (dict)
         """
-        self.request = self.makeRequest(url, method, args)
-        conn = self.makeConnection(url)
-        if DEBUG: conn.set_debuglevel(1)
-        conn.request(method, url.fullpath(), self.request.data, 
self.request.headers)
-        resp = conn.getresponse()
-        self.resp = resp
-        val = self.handleStatus(resp.version, resp.status, resp.reason)
-        if val is None:
-            data = None
-        else:
-            data = resp.read()
-        conn.close()
-        val = self.handleResponse(data)
-        return val
+        retries = 0
+        while retries < 2:
+            self.request = self.makeRequest(url, method, args)
+            conn = self.makeConnection(url)
+            try:
+                if DEBUG: conn.set_debuglevel(1)
+                conn.request(method, url.fullpath(), self.request.data,
+                             self.request.headers)
+                try:
+                    resp = conn.getresponse()
+                    self.resp = resp
+                    val = self.handleStatus(resp.version, resp.status,
+                                            resp.reason)
+                    if val is None:
+                        data = None
+                    else:
+                        data = resp.read()
+                    val = self.handleResponse(data)
+                    return val
+                except httplib.BadStatusLine:
+                    retries += 1
+                    time.sleep(5)
+            finally:
+                conn.close()
+
+        raise XendError("Received invalid response from Xend, twice.")
+
 
     def getHeader(self, key):
         return self.resp.getheader(key)
+
 
 class UnixConnection(httplib.HTTPConnection):
     """Subclass of Python library HTTPConnection that uses a unix-domain 
socket.

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.