summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2013-08-24 12:03:10 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-08-26 11:29:46 +0100
commitbfab986ccd59636d0b0e79309f020e55481b0567 (patch)
tree5db43a018da4cb21c9687d4a4c7fc8d8245ad5e4 /bitbake/lib
parenta03a423c607f53684789ebb5c3c5003568047a14 (diff)
downloadpoky-bfab986ccd59636d0b0e79309f020e55481b0567.tar.gz
bitbake: server/xmlrpc/prserv: Add sane timeout to default xmlrpc server
The standard python socket connect has long timouts which make sense for remote connections but not local things like the PR Service. This adds a timeout parameter to the common xmlrpc server creation function and sets it to a more reasonable 5 seconds. Making the PR server instantly exit is a good way to test the effect of this on bitbake. We can remove the bodged timeout in the PRServer terminate function which has the side effect of affecting global scope. (Bitbake rev: 8c01cff94787abbb64fbdf0c16cd63f8f97a7e03) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/server/xmlrpc.py22
-rw-r--r--bitbake/lib/prserv/serv.py3
2 files changed, 18 insertions, 7 deletions
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py
index 026415efd5..d290550e9f 100644
--- a/bitbake/lib/bb/server/xmlrpc.py
+++ b/bitbake/lib/bb/server/xmlrpc.py
@@ -47,15 +47,29 @@ except ImportError:
47DEBUG = False 47DEBUG = False
48 48
49from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler 49from SimpleXMLRPCServer import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
50import inspect, select 50import inspect, select, httplib
51 51
52from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer 52from . import BitBakeBaseServer, BitBakeBaseServerConnection, BaseImplServer
53 53
54class BBTransport(xmlrpclib.Transport): 54class BBTransport(xmlrpclib.Transport):
55 def __init__(self): 55 def __init__(self, timeout):
56 self.timeout = timeout
56 self.connection_token = None 57 self.connection_token = None
57 xmlrpclib.Transport.__init__(self) 58 xmlrpclib.Transport.__init__(self)
58 59
60 # Modified from default to pass timeout to HTTPConnection
61 def make_connection(self, host):
62 #return an existing connection if possible. This allows
63 #HTTP/1.1 keep-alive.
64 if self._connection and host == self._connection[0]:
65 return self._connection[1]
66
67 # create a HTTP connection object from a host descriptor
68 chost, self._extra_headers, x509 = self.get_host_info(host)
69 #store the host argument along with the connection object
70 self._connection = host, httplib.HTTPConnection(chost, timeout=self.timeout)
71 return self._connection[1]
72
59 def set_connection_token(self, token): 73 def set_connection_token(self, token):
60 self.connection_token = token 74 self.connection_token = token
61 75
@@ -64,8 +78,8 @@ class BBTransport(xmlrpclib.Transport):
64 h.putheader("Bitbake-token", self.connection_token) 78 h.putheader("Bitbake-token", self.connection_token)
65 xmlrpclib.Transport.send_content(self, h, body) 79 xmlrpclib.Transport.send_content(self, h, body)
66 80
67def _create_server(host, port): 81def _create_server(host, port, timeout = 5):
68 t = BBTransport() 82 t = BBTransport(timeout)
69 s = xmlrpclib.Server("http://%s:%d/" % (host, port), transport=t, allow_none=True) 83 s = xmlrpclib.Server("http://%s:%d/" % (host, port), transport=t, allow_none=True)
70 return s, t 84 return s, t
71 85
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py
index b854686c1a..81b4f8d069 100644
--- a/bitbake/lib/prserv/serv.py
+++ b/bitbake/lib/prserv/serv.py
@@ -186,9 +186,6 @@ class PRServerConnection():
186 self.connection, self.transport = bb.server.xmlrpc._create_server(self.host, self.port) 186 self.connection, self.transport = bb.server.xmlrpc._create_server(self.host, self.port)
187 187
188 def terminate(self): 188 def terminate(self):
189 # Don't wait for server indefinitely
190 import socket
191 socket.setdefaulttimeout(2)
192 try: 189 try:
193 logger.info("Terminating PRServer...") 190 logger.info("Terminating PRServer...")
194 self.connection.quit() 191 self.connection.quit()