fillable-pdf
fillable-pdf copied to clipboard
Gem hangs passenger phusion when trying to generate filled pdfs in controller actions
I know there are some issues with this gem and the application server or things like spring, but I figured it would not conflict with more modern application servers but that does not seem to be the case. Has anyone seen an issue with passenger phusion and generation of PDF's on the fly in controllers. I will say I did add one function to the FillablePDF class to add a function to make streaming PDF content easier.
class FillablePDF
def pdf_bytes(flatten: false)
@pdf_form.flattenFields if flatten
close
@byte_stream.toByteArray
end
end
Using puma locally everything works fine, but once the code is deployed to phusion the request hangs and eventually hangs all of the web requests to the server.
Thanks in advance for any ideas on how to make this gem place nicely with passenger.
@jdejong Did you ever find an answer to this?
@jdejong and anyone else who comes after us:
In your passenger config, put
RailsSpawnMethod conservative
I also have locally problems with puma. Rails console is good, when I try to use it in the controller its not working.
To get this working, we're using:
Apache: RailsSpawnMethod direct
Nginx: passenger_spawn_method direct;
It doesn't seem that conservative
is a valid value for the spawn method any longer (if I'm reading the Passenger documentation correctly?)
Is there something that could be changed to fix this in the gem? This issue is fairly hard to debug for people who don't know the answer yet, and it doesn't seem optimal that we need to change our web server configuration just to generate a PDF.
Does anyone know where in the gem things are hanging or why the spawn method matters?
Thanks so much for working on this!
A Phusion Passenger developer explained in this thread why Passenger hangs when Rails is used with JVM. It looks like it'll be quite difficult for me to fix, and I don't know when I'll get to doing it and whether this is something I can even fix. I've added the Deployment with Phusion Passenger + Nginx section with some workarounds (thanks @adam-scimed).
@simonfranzen If your app was hanging with Puma when used in Rails controllers, that is likely caused by an error that I fixed earlier today in version 0.9.2.
@vkononov @simonfranzen did you find a solution to make it worked in controller actions ? I have the same problem (rails 6.1, runs locally on Mac OS X), it works perfectly in console but hang forever if fillable-pdf is used in a controller action.
I tried to remove spring gems, it did not work for me.
@nflorentin Are you able to share a sample project where you are experiencing the hang? Or at least Gemfile
, Gemfile.lock
, the controller action, and the file you're trying to fill out. That would really help with debugging.
You also mentioned that it runs locally. Do you mean locally in the console? Or locally in the controller action?
Are you running the project with puma?
hi @vkononov Thanks for your answer and sorry for the lack of details in my message.
I don't have a sample project, I'm under a huge load of work so I don't know if I will be able to do it soon.
I'm using Puma. All my tests are done in development because the features are not in production yet so I don't know if that would work in production environment. To sum up, it works on my local machine in rails console but does not work on my local machine in a controller action.
@nflorentin Would you be able to share your Gemfile
and Gemfile.lock
? Also, please let me know your version of Java SDK and Mac OS. Thanks.
Thanks, @nflorentin. I noticed that your Gemfile
doesn't have a ruby version specified. Could you please let me know your Ruby version as well?
@vkononov sorry for the late answer, the project is on ruby 2.5.9
@vkononov @simonfranzen @nflorentin did you find a solution to make it work in controller actions in the development environment? I have the same problem (rails 5.2.8.1, runs locally on Mac OS X), it works perfectly in the rails console but hangs forever if fillable-pdf is used in a controller action.
I tried to remove spring gems, but it did not work for me.
Rails Version: 5.2.8.1 Puma Version: 5.6.5 Ruby Version: 2.6.3 OS: Mac OS 12.5.1 I tried with Java SE v11, v15
@fuadkhan1996 Are you able to provide an stripped down example project? I have not been able to reproduce this issue so far.
@vkononov I tried creating a sample project with the versions and Gemfile I told above. Fillable-pdf is working there but not on my office's project.
@fuadkhan1996 Then I would guess that there are other gems or configurations in your office project that are causing this issue. If I am unable to reproduce the issue, I'm afraid I cannot help you.
@vkononov I just fixed it. It was hanging because I had workers set up in my puma.rb configuration file. I removed it and fillable-pdf started working. I think using this information you can reproduce the issue.
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
@fuadkhan1996 Looks like this is caused by an issue with the rjb
gem, which is used as a dependency.