# Store SOAP::RPC::Driver in user session throws TypeError

**URL:** <https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700>\
**Category:** Rails\
**Created:** [August 7, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700 "2006-08-07T15:54:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 7, 2006, 3:54pm UTC](https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700/1 "2006-08-07T15:54:32Z")

</div>

Hi All

I have a  
requirement to consume a 3rd party web service from my Rails  
application. I am doing this  
in my action

require ‘soap/wsdlDriver’  
factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM\_WSDL\_URL)  
soap = factory.create\_rpc\_driver  
soap.wiredump\_file\_base="#{RAILS\_ROOT}/log/transidiom.log"

param = %(  
 110  
2442  
ccvdev2 ccvdev2  
ORC wmasprod  
 )

result = soap…retrieveCustomerData(param)

I get the expected result, but the real problem is performance since I  
have  
to re-create the rpc-driver to the same service on each request. So I  
try  
and store the soap object which is SOAP::RPC::Driver type.

session[:soap] = soap

and I get TypeError (singleton can’t be dumped):  
C:/ruby/lib/ruby/1.8/pstore.rb:348:in `dump' C:/ruby/lib/ruby/1.8/pstore.rb:348:in`dump’  
C:/ruby/lib/ruby/1.8/pstore.rb:326:in `transaction' C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:90:in`update’  
C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close' C:/ruby/lib/ruby/1.8/cgi/session.rb:330:in`close’  
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action\_controller/base.rb:984:in  
`close\_session’

Now ofcourse I realize that RPC Driver has some singleton object or  
anonymous class/method which can’t be serialized hence the TypeError. My  
question is what can I do to improve the performance and reduce the  
overhead  
of creating new RPC Driver objects on each request.

Thanks  
-daya

---

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 7, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700/2 "2006-08-07T17:09:42Z")

</div>

Ola, this is a Good idea but can it give rise race conditions?? or are  
there  
anyother implications which might be painful to debug/fix in the long  
run?

---

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 7, 2006, 4:03pm UTC](https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700/3 "2006-08-07T16:03:33Z")

</div>

linux user wrote:

> have to re-create the rpc-driver to the same service on each request. So  
> C:/ruby/lib/ruby/1.8/cgi/session.rb:330:in `close’  
> -daya
> 
> * * *
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

You don’t store the driver itself in the session but in global singleton  
objects. That’s the approach I used not long time ago for exactly this  
kind of problem.

I just had someting like this in my model class  
if @@driver.nil?  
@@driver = SoapWsdlDriver.new  
end  
@@driver.customWebServiceCall

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.

---

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 7, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700/4 "2006-08-07T18:18:50Z")

</div>

On 8/7/06, linux user [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > param = %(\<Request  
> > > have to re-create the rpc-driver to the same service on each request.  
> > > C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close’
> > > 
> > > removed\_email\_address@domain.invalid  
> > > @@driver.customWebServiceCall
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I have put the similar code in my ApplicationController … here is the  
code

class ApplicationController \< ActionController::Base

require ‘soap/wsdlDriver’  
factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM\_WSDL\_URL)  
@@soap = factory.create\_rpc\_driver  
@@soap.wiredump\_file\_base=“#{RAILS\_ROOT}/log/transidiom.log”

def …my actions…

I am in Development environment and the problem is that @@soap which  
should  
be initialized only once (at class instantiation time) is initialized on  
every request (I checkd the object\_id and they are different on each  
request). Being a newbie my guess is that atleast in development env  
there  
is a new instance of the controller created on every request. So my  
question  
is in Production env is there only one instance of the controller to  
serve  
all requests or is there a new instance of controller created on every  
request?

thanks in advance  
-daya

---

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 8, 2006, 3:56pm UTC](https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700/5 "2006-08-08T15:56:56Z")

</div>

I know it is very difficult to simulate and identify a race condition.  
But  
this is what I think may happen if I use class variable or even global  
variable to store SOAP::RPC::Driver object.

In production each controller is loaded only once which I assume means  
there  
is only one instance of controller serving multiple requests. Now lets  
assume that all the parameters needed to make the web service call are  
local  
to the action (method), which means these parameters are immune from  
race  
conditions since the are on the thread stack and each thread is unique  
for  
each request. But the class variable or global variable is shared across  
multiple requests, now imagine the same class variable or global  
variable  
accessed in different controllers or different actions of same  
controller.  
Hence there is a potential that the result of a webservice call may get  
mixed up, depending on who gets the returned value first.

I may completely wrong here since I don’t know about the inner working  
of  
the CGI/FCGI/Rails request handling. Can anyone please enlighten me or  
tell  
me if my fears are misplaced?

TIA

-daya

---

<div class="post-metadata">

**Author:** ![linux\_user](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@linux\_user](https://www.ruby-forum.com/u/linux_user)\
**Post date:** [August 7, 2006, 9:07pm UTC](https://www.ruby-forum.com/t/store-soap-driver-in-user-session-throws-typeerror/101700/6 "2006-08-07T21:07:11Z")

</div>

linux user wrote:

> Ola, this is a Good idea but can it give rise race conditions?? or are  
> there anyother implications which might be painful to debug/fix in the  
> long run?

Not that I know of. And there’s no race condition involved if you don’t  
have any trouble with having more than one reference to the Driver  
floating around, which shouldn’t be a problem.

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.
