-
Notifications
You must be signed in to change notification settings - Fork 790
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
Asset compilation stalls with sprockets v4 #640
Comments
Using When I branch off sprockets v4.0.0 and revert this commit asset compilation works just fine again. Hence I think the root cause of my problem lies in that commit. |
References #469 |
also bumped into this within docker... Oddly on one machine it seems to work with the exact same build / code, but another one (with more CPUs maybe slightly different architecture, both are on Digital Ocean) it hangs the asset precompile exactly the same way that @leoarnold described... Would be tricky to build a reproducible example unfortunately, but happy to run some tests etc. We just upgraded sprockets to 4.0.0 and with 3.7.2 it didn't seem to happen. |
As far as I understand #469 tried to pivot from asset compilation path after path to all paths in parallel. Therefore we need to wait for all compilers to finish before moving on: sprockets/lib/sprockets/manifest.rb Line 130 in 08fef08
This means we are waiting for all promises to complete with which can cause indefinite waiting as reported above. Waiting is a synchronized method where the underlying implementation of the locking mechanism varies with the Ruby interpreter used (but for most use cases it presumably is a mutex): It still remains to investigate what can cause a promise to never finish (i.e. its event to never become "set"). Maybe the choice of the sprockets/lib/sprockets/manifest.rb Lines 334 to 336 in 08fef08
@gingerlime Would you mind running some builds with |
@leoarnold sorry, but where exactly do I set |
related? #534 |
attached 2 |
@gingerlime I set |
@gingerlime I think I'm onto it: I think Sprockets is deadlocking because it tries to compile some assets twice in parallel. I think I missed the last paragraph of https://eileencodes.com/posts/the-sprockets-4-manifest/ where it tells you to remove the line with I just yanked that line and now Travis CI runs as expected. |
@leoarnold we removed the Here's what the PR looked like (after merging this, we started seeing those issues) |
@gingerlime To get my manifest right, I temporarily added the line pp args.flatten.map { |path| [path, environment.find_all_linked_assets(path).map(&:filename)] }.to_h in between these two sprockets/lib/sprockets/manifest.rb Lines 122 to 123 in c4b191e
and run As far as I understand, the output should look like a hash with only |
Thanks for the tip, @leoarnold. I see other keys besides For the In any case, wouldn't it be more sensible for sprockets to just walk over all unique entries if duplicates are causing deadlocks? |
@gingerlime Out of curiosity: Why do you only link the directory |
@leoarnold probably better if my colleague @joker-777 comments to confirm this, but as far as I'm aware, our main app javascript is compiled using webpack(er), but ActiveAdmin, CKEditor and our CSS and a few other bits don't support it (yet?) so they need to use the standard asset precompile process. |
@gingerlime Can you post an (obfuscated) example of your asset list with the duplicates. Maybe we can construct a failing unit test from it in order to draw some core contributers' interest to this issue. |
@leoarnold I was hoping that the strace files I shared would help pinpoint the issue? but not sure if anyone had looked at those? Anyway, here's the manifest output from adding the line as you suggested. I don't think there's anything particularly sensitive about it. All those assets are public eventually :) |
It looks like I have this stalled compilation when trying to use Sprockets 4 with Jekyll Assets 4 in Jekyll 4… |
@gingerlime AFAIK the strace can only show what is happening, but not why. In the current understanding of the problem (as per this thread right here), I think we are clear that
In your debug output I noticed that any files required It seems that you are using Does that change anything for you? My working assumption is that we need a sprockets/lib/sprockets/manifest.rb Line 125 in 08fef08
or an improvement to args.flatten.map { |path| environment.find_all_linked_assets(path).map(&:filename) } must be disjoint. |
Thanks @leoarnold we'll look into it (@joker-777?) Definitely feels like adding a |
@leoarnold Thanks a lot for your help and suggestions. Please let me know if maybe misunderstood something. You also asked, why we add /cc @gingerlime |
I've experienced the same problem. Upgrading Rails from 5 to 6 also upgraded sprockets at the same time, which complicated narrowing down the problem! Using |
slightly different on my side:
|
I have the following setup (on a Rails 6 app with both webpack and Sprockets assets), and the deadlock happens (right after
Is there a way to monkey-patch around this for the time being? Thanks. |
Same issue here. I tried unicorn, puma, thin, but each one would just deadlock with 0% CPU on the first access in development mode. Adding
to |
See also #538 which seems to be an earlier report of the same issue. I managed to narrow down a hang/deadlock in In the meantime, it seems that |
I was able to resolve this issue by regressing back to version |
I recently ran into |
I can confirm that adding |
Expected behavior
Asset compilation speed with sprockets v4.0.0 should be comparable to or faster than with v3.7.2.
Actual behavior
When calling
rails assets:clobber tmp:clear assets:precompile
sprockets will start building the cache (i.e.tmp/cache/assets/sprockets/v4.0.0/
) up to about 8 MB (full cache with v3.7.2: 18MB) with no assets written and then the process and all of its six forks seem to come to a complete halt: 0.0% CPU usage according tohtop
. The process will not react toSIGINT
orSIGTERM
any more, onlySIGHUP
andSIGKILL
can end the process.Same with assets compilation in Rails development environment upon first request.
Once sprockets cache is built, sprockets will run smooth and quick as expected, but building the cache seemingly takes forever: Travis CI will just abort the build after 10 minutes.
System configuration
Example App (Reproduction)
I couldn't quite figure out what is making sprockets stall so I am not able to provide an example app at time of this writing (project in question is private company property).
Therefore I would be very grateful if the community could provide pointers on how I could debug this and identify the root cause.
The text was updated successfully, but these errors were encountered: