-
Notifications
You must be signed in to change notification settings - Fork 53
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
Why thread locals? #41
Comments
jtmarmon@2ada527 Here's a change I made which seems harmless, and also seems to work fine, but would appreciate input on why this decision was made |
It's an attempt of making the client thread-safe and avoid leaking the current client to other threads. What are the problems you're seeing? |
At Podio, part of our application stack is a rails component that leverages the podio-rb library for communication with the API. We have an initializer that establishes the connection and a |
@cpeters we have similar code which does
but because the client is nil on every request, we're sending an HTTP request to podio for every client request. am I missing something here that would prevent that? |
Where is this code located and then executed? I'm curious about the conditional statement. Let me dig into the code because this may not actually return nil, in the ruby sense.
That is our client init. |
The difference is if you use username/password or initialize the client with a stored token. I'll do some more research but I think we can move the client to use instance variables. |
I'm missing something here. How does moving to instance variables solve the problem? Each thread will still have to authenticate with an API call. |
@cpeters it's actually not something I understand well and am doing some more research to try and understand, but my fork of podio-rb definitely fixes the issue |
think I figured out why:
this prints:
It seems that ruby class variables are both thread safe and globally available |
scratch that, they are not thread safe. but they are available across threads |
@jtmarmon I think we need to use a mutex.
http://stackoverflow.com/questions/9558192/thread-safety-class-variables-in-ruby |
Podio uses thread locals to store the client. Is there a reason for doing that instead of standard instance variables? I ask because it causes problems on certain servers.
The text was updated successfully, but these errors were encountered: