Issue 6907: xmlrpclib.make_connection() is not thread safe (original) (raw)

Created on 2009-09-14 10:20 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg92596 - (view) Author: STINNER Victor (vstinner) * (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 (vstinner) * (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
2022-04-11 14:56:52 admin set github: 51156
2009-09-15 21:28:47 kristjan.jonsson set messages: +
2009-09-14 11:15:21 vstinner set status: open -> closedmessages: +
2009-09-14 11:10:51 kristjan.jonsson set resolution: not a bugmessages: + nosy: + kristjan.jonsson
2009-09-14 10:20:20 vstinner create