-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Savon::Client and threadsafety #259
Comments
i'm pretty much getting the same result for: client = Savon::Client.new do
wsdl.document = "http://www.thomas-bayer.com/axis2/services/BLZService?wsdl"
end
threads = [70070010, 24050110, 20050550].map do |blz|
Thread.new do
response = client.request :blz, :get_bank, :body => { :blz => blz }
Thread.current[:value] = response.to_hash[:get_bank_response][:details]
end
end
sleep 10
threads.each &:kill
threads.map { |thr| thr[:value] }.compact the client creates a single request element for every request. |
sorry to reopen an old issue, but the root cause of this problem also manifests itself in some interesting difficulties in single-threaded environments. imo, it is not good for the client to hold state about a request in progress. the client should pass on the actual responsibility of forming and making requests to another class. |
can you specify the state that is causing problems and help to fix this? |
of course! just had to take some time to ensure that my hypothesis was correct. broadly, the issue is that the Client object maintains state about the request in progress, namely in the this necessarily leads to a race condition. let's consider the case of two concurrently executing threads A and B accessing the same Savon client named 'client'. thread A calls client#request at t1. there is a possibility of thread A or B not being preempted after t2 until they are done making the request, which would allow some level of isolation between requests, but this is exceedingly unlikely. the second issue is that the what to do? in my opinion, the best and cleanest way to solve this is to create a separate |
thanks for explaining. your approach sounds like a good solution and i will definitely accept your pull request. |
great! should be done either today or tomorrow... |
quick update on this: i have a build working that is thread safe. i got a bit lazy over the last weekend and it was a holiday here on monday, which meant even more laziness. :-) currently working on updating the tests, then we should be good to go. |
released with v1.2.0. |
When I have multiple concurrent requests in threads and I use the same instance of Savon::Client, the request body doesn't seem to change between requests.
I have made a small fake SOAP server as you can see here: https://gist.github.com/1725656
And I have code like this:
When I do a bunch of requests simultaneously, the endpoint reports all the same values.
When I put the creation of the client inside the thread, everything works like it should.
I am using Savon 0.9.7 and Ruby 1.9.3.
Also, I explicitly set Nori's parser to Nokogiri, but that didn't help.
Am I doing something wrong? Can you confirm this issue or is it just me? 🤘
The text was updated successfully, but these errors were encountered: