Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5.2 server hangs when not precompiling assets

We have an issue since we upgraded our project's dependency from rails 4.2 to rails 5.2

We use both Sprockets assets and Webpacker. When booting the server for the first time, and loading the first page (any page), it hangs right before serving the content of the page.

It usually hangs on a line like this, with no other output:

I, [2020-05-15T10:28:20.828146 #66077]  INFO -- : [fd7f1413-7d72-402f-92f9-95688e7fa50e]   Rendered partials/_front_page_featured_items.html.haml (172.4ms)

The ruby process seems idle, not using the CPU.

I realized that by running rails assets:precompile before running the server, then it doesn't hang anymore, even if I delete the precompiled assets in the public/assets and public/packs directory.

I can reproduce it by:

  • Deleting contents of tmp/cache

We can reproduce this on at least 3 development machines and also on CI server.

In the rails 4.2 branch, we don't have this issue, and we have the same version of Webpacker (4.2.2).

The main difference between the rails 4.2 branch and 5.2 in terms of assets is the upgrade from sprockets 3.7 to 4.0, alongside all the other dependency changes.

I am stuck debugging this and would appreciate some help in how I can further debug this issue, getting more output to the log, etc.

UPDATE: I disabled webpacker in the gemfile and it still freezes

UPDATE #2: Found a related issue on Sprockets: https://github.com/rails/sprockets/issues/640 . I believe it is the same issue as I have.

like image 636
Cristian Avatar asked May 15 '20 09:05

Cristian


1 Answers

The issue seems to get fixed after adding:

if Rails.env.development? || Rails.env.test?
  Sprockets.export_concurrent = false
end

to application.rb

According to https://github.com/rails/sprockets/issues/640, there is a bug in Sprockets where a deadlock can happen, and this is a workaround fix.

like image 131
Cristian Avatar answered Oct 18 '22 00:10

Cristian