Search code examples
ruby-on-rails-3jrubypopenwkhtmltopdf

jruby IO.popen read hangs in action when requests are made to the local dev server


I just want to send the output of wkhtmltopdf to the user. It shouldn't be so hard.

def it
    send_pdf "file.pdf"
end

def send_pdf(file)
  url= url_for(params) # Example: http://localhost:3000/report/it
  webkit= Rails.root.join('app', 'bin', 'wkhtmltopdf', 'current')
  cmd= "#{webkit} -q \"#{url_for(params)}\" -"

  data= IO.popen(cmd).read ############### HANGS HERE ###################

  send_data(data, type: "application/pdf", filename: file)
end

Why does it hang and how to fix it?


Solution

  • I think the clue here may be it's a local development server - so maybe it can only accept one request at a time.

    To test, try getting the html from somewhere else:

    def send_pdf(file)
      # [...]
      cmd= "#{webkit} -q http://brighterplanet.com -"
      # [...]
    end
    

    If that works, then the answer to your question is that the development server is "single-threaded".