classification
Title: xmlrpclib.make_connection() is not thread safe
Type: behavior Stage:
Components: Extension Modules Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: haypo, kristjan.jonsson
Priority: normal Keywords:

Created on 2009-09-14 10:20 by haypo, last changed 2009-09-15 21:28 by kristjan.jonsson. This issue is now closed.

Messages (4)
msg92596 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2009-09-14 10:20
The issue #6099 (part of #6267 superset) introduced a regression:
xmlrpclib.make_connection() is not thread safe. If xmlrpclib is used in two
threads, the socket is shared, but it doesn't any lock, and so data will be
mixed between the two requets. It becomes worse when I use SSL (pyopenssl
or m2crypto).

A possible solution is to use a different socket for each thread.

Note: I really love #6099, it was exactly what I needed :-)
msg92603 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2009-09-14 11:10
the xmlrpclib.ServerProxy is not thread safe, no.  Nor is it designed to 
be.  the documentation never claims that it is and the fact that the old 
version was (due to a new HTTPConnection being created each time) is a 
coincidence than a design feature.
In my own client code I use a pool of ServerProxy objects for each 
thread to claim and use one at a time.  This way I can have many 
simultaneous requests to the same server going.
You can also create your own lock and share a ServerProxy among threads.

Also note that HTTPConnection is not thread safe either.  And in 
general, class instances in the lib are not thread safe unless 
explicitly documented to be so.
msg92605 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2009-09-14 11:15
@krisvale: You changed the resolution to invalid, but you leaved the state
unchanged (open). Ok, I agree that the stdlib is not thread safe, and so I
closed this issue.

I saw this issue as a regression because the previous version (using a different
socket for each XML-RPC request) was thread sae (even if it wasn't designed
to be thread safe) :-)
msg92657 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2009-09-15 21:28
Ah yes.
Sorry, I'm no good with this system.  Thanks.
History
Date User Action Args
2009-09-15 21:28:47kristjan.jonssonsetmessages: + msg92657
2009-09-14 11:15:21hayposetstatus: open -> closed

messages: + msg92605
2009-09-14 11:10:51kristjan.jonssonsetresolution: not a bug

messages: + msg92603
nosy: + kristjan.jonsson
2009-09-14 10:20:20haypocreate