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

Sprockets 3.3.X using old cached files #127

Closed
juliantai opened this issue Sep 1, 2015 · 18 comments
Closed

Sprockets 3.3.X using old cached files #127

juliantai opened this issue Sep 1, 2015 · 18 comments

Comments

@juliantai
Copy link

When I run cap staging deploy or RAILS_ENV=staging bundle exec rake assets:precompile on my staging/production server I get an old cached version of files I have modified.

Changing the Rails.config.assets.version causes the cache to be invalidated as expected.

Downgrading to 3.2.0 and lower fixes the issue.

I did some digging and it look like my issue is coming from Loader module.

@schneems
Copy link
Member

schneems commented Sep 2, 2015

Use 3.3.4

@juliantai
Copy link
Author

Thanks! I tried 3.3.4 and it fixes the caching issue.

Regarding deploying to production it looks like it is still looking for files in old folders. I tried to running RAILS_ENV=production rake assets:clean, but it didn't work.

Will I need to run RAILS_ENV=production rake assets:clobber to fix this issue?

Note the date is from a couple days ago as opposed to being today's date 20150902XXXXXX.
DEBUG [5ee0e4cf] Errno::ENOENT: No such file or directory @ rbsysopen - /home/deployer/apps/map_app/releases/20150827232656/app/assets/images/ajax-50x50.png DEBUG [5874e899]

Edit: I updated the config.assets.version in my production.rb file and it fixed it.

@schneems
Copy link
Member

schneems commented Sep 2, 2015

💥

@schneems
Copy link
Member

schneems commented Sep 2, 2015

Thanks for the report, i'm glad it's working for you now.

I think there still might be a bug here. Part of the cache key includes the version of sprockets that was used when you compiled so i'm not sure why you had to rev the version.

@joker-777
Copy link

Hi, we experiencing the same issue. Unfortunately updating to 3.3.4 doesn't help us. Also updating the assets.version only helps for the next deploy which obviously takes quite long. The next deploy after this has again this problem

@juliantai
Copy link
Author

Yeah I found that out the next day. I ended up using 3.2.0 for now.

@schneems schneems reopened this Sep 8, 2015
@schneems
Copy link
Member

schneems commented Sep 8, 2015

I re-opened the issue. Can either of you give me an example app that reproduces the problem? I can't fix what I can't reproduce, an example app would be hugely helpful.

@wlipa
Copy link
Contributor

wlipa commented Sep 9, 2015

I was able to reproduce the problem under 3.3.4 with a scenario like the following:

app/assets/outer.js
//= require inner.js

rake assets:clobber
deploy app
works properly
make a change A to inner.js
deploy app
works properly, the change was picked up
make a change B to inner.js
deploy app
broken, we are still serving up outer.js with embedded inner.js change A, even though change B is actually in the deployed files

It's part of a big app so it's hard to minimize. I'm happy to add log statements or debug it further if you can suggest things to look for.

@joker-777
Copy link

I will try to create an example app the next days. Will come back then.

@alepore
Copy link

alepore commented Sep 10, 2015

i also have this problem with both 3.3.3 and 3.3.4. but didn't investigate much yet

@joker-777
Copy link

@schneems I'm still trying to create an example app but couldn't reproduce it yet. I have one question thought. We still use the old extension format file.js.coffee for our coffeescript files. Could this be a problem?

@wlipa
Copy link
Contributor

wlipa commented Sep 22, 2015

I discovered that rake assets:clobber wasn't actually clobbering the assets in my deployed environment (see #140), but unfortunately the stale asset problem still happens even with a manual clobber.

It's quite reproducible in the deployed environment, but does not reproduce on my local dev box, even with the exact same revisions and with the Rails env set to the deployed environment temporarily.

@jeremy
Copy link
Member

jeremy commented Sep 22, 2015

@wlipa You may be able to reproduce in development by making a copy of your app dir, symlinking the copy's tmp/cache and public/assets to the original tmp/cache and public/assets, then making a change to an asset in the copy and trying to precompile. That mirrors a Capistrano style deploy where a new release directory is seeing cached assets rooted in the previous release directory.

@wlipa
Copy link
Contributor

wlipa commented Sep 22, 2015

Thanks for the suggestion. I tried that but it still works correctly on my dev box.

@wlipa
Copy link
Contributor

wlipa commented Sep 22, 2015

One thing I find rather baffling is the way that cached dependencies contain references to the deployment release. For example:

file-digest:///home/ops/apps/alpha.example.com/releases/20150922215431/app/assets/javascripts/preferences.js

Doesn't referring directly to old releases that are still on the filesystem mean that we aren't picking up changes to these assets, because the dependency resolution code will calculate the digest based off the contents of the old asset? I would expect the dependency to be:

file-digest:///home/ops/apps/alpha.example.com/current/app/assets/javascripts/preferences.js

@jeremy
Copy link
Member

jeremy commented Sep 23, 2015

@wlipa Exactly, yes. This is why @schneems has been converting absolute paths to relative paths.

@wlipa
Copy link
Contributor

wlipa commented Sep 23, 2015

I think what may be happening is the line in loader.rb fetch_asset_from_dependency_cache that does an in-place expansion of the dependency paths for preexisting history is not getting undone in the scenario where we fall though to the second half of the function.

deps.map! { |path| path.start_with?("file-digest://") ? expand_from_root(path) : path }

is an in-place modification of the history array of dependencies. There's a line in that second half which does path compression but only on the current asset. There's nothing that undoes the expand_from_root above.

uri.start_with?("file-digest://") ? compress_from_root(uri) : uri

So when the unshift happens, some absolute paths can get into the history cache.

cache.set(key, history.unshift(deps).take(limit))

@jeremy
Copy link
Member

jeremy commented Sep 27, 2015

Fixed @ #141, #142, #143.

@jeremy jeremy closed this as completed Sep 27, 2015
johnnaegle added a commit to johnnaegle/sprockets-bug that referenced this issue Oct 22, 2015
…#127

and convience myself that upgrading to 3.4 fixes the production problem we were seeing.
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

No branches or pull requests

6 participants