chargebee / chargebee-ruby

Ruby library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=ruby
MIT License
32 stars 60 forks source link

Make configuration safe across multi threaded environments #10

Closed beirigo closed 8 years ago

beirigo commented 8 years ago

Currently, the configuration is being stored as a class level variable. That renders the gem thread unsafe. This might be OK if you're using it from rails on a simple setup with single threaded requests, But if you're running multi-threaded rack servers like Puma or Thin, or even a background job processor like Sidekiq, you might run into trouble.

This change consists into storing the configuration on Thread.current instead of a class variable. The choice for the request_store gem makes sense since it provides a rack middleware to clear Current.thread after each request.

I understand that this might be an issue since some people are probably configuring the gem on a initializer instead of doing it at a request level. But if you have more than one ChargeBee site (as I imagine most people will) and you call ChargeBee.configure on each request, this change will not affect you at all.