Hi All
I am newbie to Rails… and I am trying to invoke a third party
webservice
using SOAP::RPC::Driver object. Now I can’t store that in session (it
throws
TypeError) so the next best thing (on the suggestion by Ola
from this mailing list) I am storing it in Class variable or I can
store this rpc_driver object in global variable.
In brief my concerns are related to race conditions that may arise if I
store resusable objects in class/global variables.
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