wicked_pdf: freezes

Hi,

So I’m using the current master head and have this code:

  def show
    respond_with claim do |format|
      format.pdf do
        render pdf: claim.number.gsub(/[^0-9a-z]/i, '_'), layout: 'print.html'
      end
    end
  end

and once it gets to here:

"***************\"/usr/local/bin/wkhtmltopdf\" -q        - - ***************"

It just freezes. When I kill the server with ctrl + c it then renders the pdf… any ideas on what’s going wrong?

Many thanks

p.s. I’m using the latest home brew version /usr/local/Cellar/wkhtmltopdf/0.11.0_rc1

About this issue

  • Original URL
  • State: open
  • Created 12 years ago
  • Comments: 32

Most upvoted comments

For those using Puma and wkhtmltopdf - @JuanitoFatas made a good point with 2+ workers. Puma uses round-robin with some load-balancing algorithm to distribute incoming requests. For some reason (I believe it can be perfectly justified) Puma may send some incoming requests to the same busy worker involved in PDF generation. If you have a bunch of assets and just a few or less workers - there’s a good chance that some asset request will be sent to the PDF worker locking the whole thing up. I believe this may be somehow tuned up, but a quick solution is to just spin up more workers temporarily while working on PDF-related stuff, eg.

puma -w 16 -p 3000

I believe similar concept may relate to other app servers. Hope this helps!

Works for me with 127.0.0.1:3000 instead of localhost:3000

For people who use Puma. You need at least 2 process worker. With only 1 worker it will freeze. Change to 2 workers worked for me. The number of process workers can be set in config/puma.rb.

@chorstikus you saved the day. This worked for me:

config.action_controller.asset_host = 'http://127.0.0.1:3000'

Now all of our asset_url paths are working correctly and automatically with wickedpdf, without having to use any wicked helpers.


Side note: this worked perfectly running the puma command (because puma by default binds to 0.0.0.0) but using rails s we had to override the default Rails setting to respond to 127.0.0.1 as well, like so:

# add to the bottom of config/boot.rb, RAILS 5 ONLY
require 'rails/commands/server'

module DefaultOptions
  def default_options
    super.merge!(Host: '0.0.0.0')
  end
end

Rails::Server.prepend(DefaultOptions)

For other versions of Rails, see this Stack Overflow answer: https://stackoverflow.com/a/29946020/1742070