Skip to content
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

Remove autoload code, it's not thread safe #919

Closed
wants to merge 3 commits into from

Conversation

tinco
Copy link

@tinco tinco commented Feb 10, 2015

Hi guys,

We've been running into problems with the autoloads in grape. When running grape in a multithreaded app server it would have multiple concurrent requires which can lead to all sorts of nasty conditions.

I couldn't discover a way to put in thread safe mode so I just removed all the autoloads.

Do you have any other concerns with running Grape in a multithreaded app server?

@tinco
Copy link
Author

tinco commented Feb 10, 2015

Woops, pardon me this doesn't work yet, I still have to reorder the dependencies and run the suite. Just submitting the PR as a discussion point for now :)

@tinco
Copy link
Author

tinco commented Feb 10, 2015

Alright, specs pass this way :)

@dblock
Copy link
Member

dblock commented Feb 10, 2015

Hmm, this will likely break people's workflow. How do other projects deal with this? Can we make Grape thread-safe(r) instead or turn auto-load off in production?

Either way it needs a CHANGELOG entry.

@tinco
Copy link
Author

tinco commented Feb 10, 2015

Mr Tenderlove has a blog article about it here:

http://tenderlovemaking.com/2012/06/18/removing-config-threadsafe.html

In ActiveSupport is a module called Autoload, it has a helper method that allows you to call eager_load on modules. What Rails does is including that module and then when config.thread_safe! is set, call it amongst other things.

The module is really tiny, you could opt for that as well, it would disrupt peoples workflows a bit less I suppose.

@dblock
Copy link
Member

dblock commented Feb 10, 2015

Grape already requires ActiveSupport, so maybe base it on that?

@tinco
Copy link
Author

tinco commented Feb 10, 2015

Definitely, I'll push -f a version that uses that when I get the time, in the mean time I've ran into a thread safety bug in activerecord as well, so enabling multithreading is fun times all around for us ;)

@dm1try
Copy link
Member

dm1try commented Feb 13, 2015

AFAIK, autoload is thread-safe in CRuby 2.0+. Am I wrong?

@tinco
Copy link
Author

tinco commented Feb 15, 2015

It is yes, but only in the sense that Ruby won't load the same file twice in the same thread. Race conditions and deadlocks might still occur. In any case, we are still locked on 1.9 for at least a couple of months. If you wanna go for just 2+ support then that's ok as well, we'll just keep using this fork in the meanwhile.

@dblock
Copy link
Member

dblock commented Feb 16, 2015

Thanks @dm1try. I definitely don't want to merge this "as is", I would however merge something that plays nice with ActiveSupport autoload options. Will leave this open.

@tinco
Copy link
Author

tinco commented Feb 24, 2016

PR #980 fixes this I believe

@tinco tinco closed this Feb 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants