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

Fix storing absolute path in cache (again) #547

Merged
merged 1 commit into from
Mar 10, 2018

Conversation

schneems
Copy link
Member

@schneems schneems commented Mar 9, 2018

This bug shows up like this:

Sprockets::FileNotFound: could not find file: /tmp/dir_1/codetriage-62a1c/app/assets/images/logo.svg
/tmp/dir_2/codetriage-58449/vendor/bundle/ruby/2.4.0/gems/sprockets-4.0.0.beta6/lib/sprockets/loader.rb:102:in `load_from_unloaded'
/tmp/dir_2/codetriage-58449/vendor/bundle/ruby/2.4.0/gems/sprockets-4.0.0.beta6/lib/sprockets/loader.rb:59:in `block in load'

It looks like logo.svg does not exist, but it is definitely in app/assets/images/. You'll notice that the path is different in the error /tmp/dir_1 instead of /tmp/dir_2 in the backtrace. This is a caching bug that shows up when the project directory is compiled in a different path than the last time it was compiled. This happens on Heroku often since every build happens in a unique directory name.

This bug was introduced in #441. In that PR the to_load and to_link sets are used to store assets that will be loaded or linked. At the time of implementation it was thought that the key was removed in the Bundle processor before being stored in the cache. Unfortunately this is not the case as Sprockets pipelines are confusing and the Bundle processor gets called in the “self” pipeline which does not get called until after the “default” pipeline produces an asset that is stored to the cache.

This PR fixes this issue by forcing the path into a relative path before being put in the cache, and then expanding from relative path after reading from cache.

I also added a test that should catch if any absolute values make their way into the cache, not just in the keys that we specify.

Introduced in #441 the `to_load` and `to_link` sets are used to store assets that will be loaded or linked. At the time of implementation it was thought that the key was removed in the Bundle processor before being stored in the cache. Unfortunately this is not the case as Sprockets pipelines are confusing and the Bundle processor gets called in the “self” pipeline which does not get called until after the “default” pipeline produces an asset that is stored to the cache.

This PR fixes this issue by forcing the path into a relative path before being put in the cache, and then expanding from relative path after reading from cache.

I also added a test that should catch if __any__ absolute values make their way into the cache, not just in the keys that we specify.
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.

1 participant