rails: assets:precompile freezes after 10 minutes

I have a problem with assets:precompile. It freezes after 10 minutes of precompiling assets. Process ends but it still waits for something and no response given.

INFO [2fc05e34] Running ~/.rvm/bin/rvm 2.0.0-p247@apptamers do bundle exec rake assets:precompile on x12s2.staging.apptamers.com
DEBUG [2fc05e34] Command: cd /home/webservice/project/20140129075713 && ( RAILS_ENV=production ~/.rvm/bin/rvm 2.0.0-p247@apptamers do bundle exec rake assets:precompile )
DEBUG [2fc05e34]    /home/webservice/.rvm/rubies/ruby-2.0.0-p247/bin/ruby /home/webservice/project/shared/bundle/ruby/2.0.0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets

CPU is 100% usage but it’s normal when I precompile assets on this server.

I have set up ssh_config entries to make sure that it’s not a ssh problem. So it’s not a timeout problem.

$ cat ~/.ssh/config 
Host *
   ServerAliveInterval 15

I wonder if it’s not a sshkit problem and maybe someone has the same issue.

capistrano-rails 1.1.0
capistrano       3.0.1
sshkit           1.3.0

When I do CTR+C after 1h, i get:

/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:15:in `join'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:15:in `map'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:15:in `execute'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/coordinator.rb:21:in `each'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/sshkit-1.3.0/lib/sshkit/dsl.rb:8:in `on'
/home/user/.rvm/gems/ruby-2.0.0-p247@apptamers/gems/capistrano-rails-1.1.0/lib/capistrano/tasks/assets.rake:60:in `block (3 levels) in <top (required)>'
...

This runners/parallel.rb looks interesting, maybe this is a sshkit runner problem?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 32 (10 by maintainers)

Most upvoted comments

Adding keepalive: true to ssh_options fixed my problem.

@lukaszsliwa - Thanks - your solution of adding
config.assets.logger = Logger.new $stdout to production.rb worked for me!

Problem solved by adding

ClientAliveInterval 30
ClientAliveCountMax 10

to /etc/ssh/sshd_config on the server. It seems the sshkit gem used by Capistrano responds to these SSH probes, which makes it work. I chose every 30 seconds, because one of the network equipment, between our collaborator in Spain and the servers in France, seems to be quite aggressive to cut apparent inactive connections.

I have added:

# config/environments/production.rb
config.assets.logger = Logger.new $stdout

and now it responses, shows assets precompilation log and capistrano successfully finishes a deploy. It doesn’t freeze like before.

In general, it doesn’t solve a problem (what if someone doesn’t want to see the log?) but it works.

Hi @yourivdlans. I ran the test you requested and got these results:

Test Time elapsed
Immediately redeploy the same SHA 15 seconds
Change one SCSS file (not a partial) and deploy 18 seconds
Change a partial SCSS file (one that is @imported by all 500 stylesheets) 18 minutes

As expected, if a change affects all stylesheets, they all need to recompiled. If a change is local to a small number of stylesheets, the sprockets cache is used and compilation is fast.

(To ensure the sprockets cache works, you need tmp/cache in your capistrano :linked_dirs so that the cache is reused between deploys.)

This is an argument for avoiding global variables and mixins when structuring your Sass projects, and using @import sparingly, as I’ve written about here: http://blog.55minutes.com/2013/01/lightning-fast-sass-reloading-in-rails-32/

Have you tried enabling net-ssh keepalive? Something like this might work:

server "example.com",
       :user => "deployer",
       :roles => %w(web app),
       :ssh_options => {
         :keepalive => true,
         :keepalive_interval => 60 #seconds
       }