csquared / IMGKit

Uses wkhtmltoimage to create JPGs and PNGs from HTML
Other
726 stars 104 forks source link

IMGKit hangs when calling to_img(:jpg) method with rails s #84

Closed liqites closed 9 years ago

liqites commented 9 years ago

Environment

ruby -> 2.0.0-p247
rails -> 4.0.13
OS X -> 10.10.4
imgkit -> 1.6.1
wkhtmltoimage -> 0.12.2.1

Start server with rails s

Using in Controller

def to_image
  html_string = render_to_string("images/index.html.erb") # a very simple page with a <p></p>
  kit = IMGKit.new(html_string)
  kit.to_file("tmp/xxx.kpg") #hangs here!!!
  ...
end

Additional Information

liqites commented 9 years ago

Sorry man, stupid question. I think reason is bellow:

Dead Lock, LOL

phackwer commented 6 years ago

I don't get it?! Is it solved? How?! I'm having similar problems here.

liqites commented 6 years ago

@phackwer That's because at that time, year 2015. My rails s only starts in single process mode.

Assumes that the only process called Process A, the progress will be like this:

  1. Client send request --> Process A handle the request.
  2. In Process A, it calls IMGKit to send another request to my rails server to render view for generating image and it waits.
  3. Since Process A is waiting and I do not have another process to handle the IMGKit request.
  4. My server hangs because of this.

Solution

You need to start your rails s server MULTIPLE PROCESSES or MULTIPLE THREADS mode

phackwer commented 6 years ago

Hi @liqites . Well, I'm using the Phusion/Passenger docker container (https://github.com/phusion/passenger-docker). How can I check if this is happening?

I'm having the most unusual problem here: when running a docker container locally in development mode, that has IMGKit, my code runs smooth, and generates the images properly. But when we go to the QA server, the QA hangs in the second request. wkhtmltoimage seems to get stuck, with no hope to ever come back. If I go into the docker container and kill the process manually (killall wkhtmltoimage-amd64) rails start responding other requests.

Now: what is really bizarre: if I call the endpoints that generate the images directly from my browser, al go, all normal... There is nothing special on the headers, actually it's a pretty standard get with the token in the URL, so there should be no problem at all with it!

Also, the same code that generates the images is used in a different part of our system (as we created it as a concern to be used on different controllers), and they are all working fine!!!

liqites commented 6 years ago

@phackwer

Below is some more info I need to know for figuring out the question.

1. You said IMGKit code works smooth in locally development mode

My Question is:

2. QA server problem.

Question is:

I can't determine the answer without those information.