Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Explicit require of autoloaded class triggers double load #2510
Explicitly requiring a class that's also marked to autoload can result in that class getting loaded twice. Normally that's not a huge problem, but in cases where the class undefs methods or something else similar it's an issue.
Here's a simple example created from a real-world ActiveSupport 4.1.8 issue I hit:
This is a big job. Here's what we know.
JRuby 1.7 and 9k require logic looks mostly identical, so I don't think this is a bug in require. Most likely this is a bug that has always existed in how we search for loaded and loading features, and it is being exposed now because 9k is (properly, I think) expanding absolute paths at various places during load.
I started looking into MRI's logic, and it has many differences from ours.
I'm attempting a partial port, but I have other responsibilities that will pull me away from this.
I started the port of search_required. Here's what I have: https://gist.github.com/headius/a78c68145e2f8c739b1e
This is mostly finished except for the goto in there.
The big snag came while attempting to port rb_feature_p, due to differences in our feature_index and how we maintain it.
We also don't have an expanded load_path as in MRI. They use this expanded load_path cache for trying different filesystem prefixes.
On the up side, if we manage to port all this logic over it could speed up require/load searching too.