-
Notifications
You must be signed in to change notification settings - Fork 128
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
Autoloading and Rails #235
Comments
Good Monday @bhelx Let me know your thoughts on the above and I would be happy to get this moving. |
Thanks @pmorton Will be taking a look today |
Okay, from what I can tell, our Railtie is pretty old and this library was written when using threaded servers was less common. So it's no wonder there are some issues. At first glance I would definitely say I want to dump autoload (option 1). I find messing with ruby's requires to be a little to opaque and I never liked that this library adopted autoload. I also agree that the performance penalty will be negligible. I'd be happy to look over your PR or help you get it working. |
Great. I will get this moving. Cheers! |
We are getting some strange exceptions from the recurly railtie each time we deploy our application. The app is rails 4.2 with puma running with 2 clustered mode workers with 16 threads. When the application is deployed the first call into our app (any controller) will trigger the following exception:
NoMethodError: undefined method
accept_language=' for Recurly::API:Class` and a massive stack trace in what looks like the request filter phase. This generally does not make sense because the method is defined. After much research, it seems that this is probably an issue with the use of autoload.https://bugs.ruby-lang.org/issues/921 confirms that for 1.9.3 and older, autoload is not thread safe while 2.x is. Further @headius seems to indicate that autoload is only thread safe is the same autoload mechanism is used across the board. headius/thread_safe#15 (comment). So here is where I believe that issue to be: Rails uses it's own autoloading systems, while this gem uses another. There is some race condition that is causing the
Recurly::API
class to only be partially loaded when it is called.To address this issue we could take one of a couple of approaches
extend ActiveSupport::Autoload if defined?(ActiveSupport::Autoload)
. The net result is that the activesupport autoloader which is used by rails would also be used by this gem. Doing this would allow lazy loading for ruby files in development and eager loading in production.I believe that 1 is the simplest with very little performance tradeoff, but if load performance is important to you option 2 would work as well. Let me know what you think. I am happy to code this up.
The text was updated successfully, but these errors were encountered: