rubiii/savon — Issue #259: Savon::Client and threadsafety
Author: iain
Created: 2012-02-02 22:26:51+00:00
State: open

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:

``` ruby
client = Savon::Client.new do
wsdl.document = "some.wsdl"
wsdl.endpoint = "http://localhost:13010" # my test server
end

threads = some_array.map do |parameters|
Thread.new do
response = client.request(:action_name) { soap.body = parameters }
Thread.current[:value] = response.to_xml
end
end

sleep 3 # some arbitrary timeout, giving the threads time to run
threads.each &:kill
values = threads.map { |thr| thr[:value] }.compact
```

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? :metal: