Change in vdsm[master]: concurrency: Vdscli uses a new HTTP conn per req.

asegurap at redhat.com asegurap at redhat.com
Mon Nov 19 15:13:05 UTC 2012


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: concurrency: Vdscli uses a new HTTP conn per req.
......................................................................

concurrency: Vdscli uses a new HTTP conn per req.

Python-2.7 changed xmlrpclib's implementation detail of spawining
a new http/https connection per each request to add support for
Keepalive. Unfortunately, this implementation detail was also what
made the xmlrpclib's Transport be thread-safe.

This change reverts the change in Transport, thus mantaining the
thread-safety of our python client code for unencrypted
communications.

Change-Id: Ifb08df759051bb340423958280e88df5792e9ed2
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M vdsm_cli/vdscli.py.in
1 file changed, 21 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/29/9329/1

diff --git a/vdsm_cli/vdscli.py.in b/vdsm_cli/vdscli.py.in
index 2af41b7..9d5d8a3 100644
--- a/vdsm_cli/vdscli.py.in
+++ b/vdsm_cli/vdscli.py.in
@@ -19,7 +19,8 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
-import xmlrpclib
+from xmlrpclib import Server, ServerProxy, Transport
+import httplib
 import subprocess
 import os
 from vdsm import SecureXMLRPCServer
@@ -28,6 +29,21 @@
 d_tsPath = '@TRUSTSTORE@'
 d_addr = '0'
 d_port = '54321'
+
+
+class SingleRequestTransport(Transport):
+    '''Python 2.7 Transport introduced a change that makes it reuse connections
+    by default when new connections are requested for a host with an existing
+    connection. This class reverts the change to avoid the concurrency
+    issues.'''
+
+    def make_connection(self, host):
+        '''Creates a new HTTPConnection to the host.'''
+        # create a HTTP connection object from a host descriptor
+        chost, self._extra_headers, x509 = self.get_host_info(host)
+        #store the host argument along with the connection object
+        self._connection = host, httplib.HTTPConnection(chost)
+        return self._connection[1]
 
 
 def __guessDefaults():
@@ -109,10 +125,11 @@
 
         transport = TransportClass(key_file=KEYFILE,
                                    cert_file=CERTFILE, ca_certs=CACERT)
-        server = xmlrpclib.ServerProxy('https://%s' % addrport,
-                                       transport=transport)
+        server = ServerProxy('https://%s' % addrport,
+                             transport=transport)
     else:
-        server = xmlrpclib.Server('http://%s' % addrport)
+        server = Server('http://%s' % addrport,
+                        transport=SingleRequestTransport(use_datetime=0))
     return server
 
 if __name__ == '__main__':


--
To view, visit http://gerrit.ovirt.org/9329
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb08df759051bb340423958280e88df5792e9ed2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>


More information about the vdsm-patches mailing list