Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gem hangs passenger phusion when trying to generate filled pdfs in controller actions #18

Closed
jdejong opened this issue Mar 6, 2021 · 18 comments

Comments

@jdejong
Copy link

jdejong commented Mar 6, 2021

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.

@timseal
Copy link

timseal commented Apr 21, 2021

@jdejong Did you ever find an answer to this?

@timseal
Copy link

timseal commented Apr 21, 2021

@jdejong and anyone else who comes after us:
In your passenger config, put
RailsSpawnMethod conservative

@simonfranzen
Copy link

I also have locally problems with puma. Rails console is good, when I try to use it in the controller its not working.

@adam-scimed
Copy link

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!

@vkononov
Copy link
Owner

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.

@nflorentin
Copy link

nflorentin commented Jun 15, 2022

@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.

@vkononov
Copy link
Owner

@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?

@nflorentin
Copy link

nflorentin commented Jun 15, 2022

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.

@vkononov
Copy link
Owner

vkononov commented Jun 15, 2022

@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.

@nflorentin
Copy link

nflorentin commented Jun 16, 2022

Sure @vkononov.

I'm on Mac OS 10.15.7, Java 8 update 311.

Gemfile.lock
Gemfile

@vkononov
Copy link
Owner

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?

@nflorentin
Copy link

@vkononov sorry for the late answer, the project is on ruby 2.5.9

@fuadkhan1996
Copy link

fuadkhan1996 commented Sep 14, 2022

@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

Gemfile
Gemfile.lock

@vkononov
Copy link
Owner

@fuadkhan1996 Are you able to provide an stripped down example project? I have not been able to reproduce this issue so far.

@fuadkhan1996
Copy link

@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.

@vkononov
Copy link
Owner

@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.

@fuadkhan1996
Copy link

fuadkhan1996 commented Sep 14, 2022

@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)

@vkononov
Copy link
Owner

@fuadkhan1996 Looks like this is caused by an issue with the rjb gem, which is used as a dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants