fillable-pdf icon indicating copy to clipboard operation
fillable-pdf copied to clipboard

Hangs when deployed to Heroku running Puma

Open Bajinai opened this issue 6 years ago • 19 comments

Using the app with Puma locally works perfectly, but hosting it on Heroku (with Puma as well) makes the code hang, whenever FillablePDF.new is called. Have you experienced the hanging with Puma as well?

Bajinai avatar Aug 16 '18 13:08 Bajinai

The hanging problem is something I've been investigating for a long time, but so far I have not had any success fixing it. I've never tried deploying an app with this gem to Heroku, but I have one running on CentOS 7 using Nginx with a reverse proxy to Puma, and it doesn't have any problems. I actually wanted to try Heroku hosting before, but couldn't figure out how to tell Heroku to use both Ruby and Java. Can you tell me how you did so I could investigate?

vkononov avatar Aug 16 '18 15:08 vkononov

We are running our Ruby app on Heroku, and have then added the https://github.com/heroku/heroku-buildpack-jvm-common buildpack which installs JDK, hope that helps your investigation!

Bajinai avatar Aug 17 '18 06:08 Bajinai

Hi, for information I'm also using Puma on Heroku and it works perfectly so far, I don't know if you fixed it but no problem here. Thanks for this amazing gem

Best

yv3s avatar Nov 14 '18 15:11 yv3s

Thanks, @yv3s. Glad it's working. I haven't had time do proper testing on this issue yet. Hopefully, the problem was with Heroku itself or an older version of Puma. @Bajinai, is it working for you too?

vkononov avatar Nov 15 '18 22:11 vkononov

Closing this issue, as it has not received any activity for almost a year.

vkononov avatar Sep 03 '19 21:09 vkononov

hi @vkononov, thanks for coming up with a gem to make filling up PDF easier. However, I could confirm this is still an issue for Ruby 2.6.3, Rails 6.0.2.1, I am using Unicorn as app server, and it hangs in rails console once I tried to load PDF with FillablePDF.new 'a.pdf'

leomayleomay avatar Dec 27 '19 04:12 leomayleomay

however, it works perfectly under bare irb instead of rails console

leomayleomay avatar Dec 27 '19 04:12 leomayleomay

Hi @vkononov, I'm having the same issue with Ruby 2.5.3. and Rails 5.2.4 where FillablePDF.new hangs in rails console but works fine with irb. I've done a bit of investigation and it looks like this is the line that's hanging: https://github.com/vkononov/fillable-pdf/blob/master/lib/fillable-pdf.rb#L25

Hope this helps! Thanks for your work on this.

dkleiman avatar Jan 31 '20 17:01 dkleiman

however, it works perfectly under bare irb instead of rails console

I have the same problem. Did you find a solution for that?

MatUrbanski avatar Mar 23 '20 15:03 MatUrbanski

I also have the same issue. Is there a fix or a work around?

jaehocho avatar May 24 '20 05:05 jaehocho

@leomayleomay @MatUrbanski Could you let me know if you're still having the issue with the 0.9.0 version of the gem? Thanks!

vkononov avatar May 25 '20 19:05 vkononov

@vkononov I'm still having the same issue. In the IRB everything is working fine, but when I try to use it in rails console then it freezes: Zrzut ekranu 2020-05-29 o 11 40 30

MatUrbanski avatar May 29 '20 09:05 MatUrbanski

@vkononov It seems that I found what is causing an issue. From my Gemfile I removed spring gem:

  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'

and now gem is working fine in rails console:

Zrzut ekranu 2020-05-29 o 11 52 51

MatUrbanski avatar May 29 '20 09:05 MatUrbanski

Thanks, @MatUrbanski. I'll update the README with your findings.

vkononov avatar May 29 '20 21:05 vkononov

Has anyone found a solution for this?

I had this issue on my local environment (MacOS) and was able to fix it by upgrading itext version.

However, now I am having the same issue on Heroku deploy. in FillablePDF initializer, it hangs. I was able to put logging to find out that it hangs PDF_WRITER.new method.

Interestingly, it works fine on Rails console on heroku. I saw @MatUrbanski fixed by removing spring gem, but I don't have that. Perhaps it's a conflict with another gem? Really strange.

def initialize(file_path)
  raise IOError, "File at `#{file_path}' is not found" unless File.exist?(file_path)
  @file_path = file_path
  begin
    @byte_stream = BYTE_STREAM.new
    @pdf_reader = PDF_READER.new @file_path

    # the code hangs here ################################
    @pdf_writer = PDF_WRITER.new @byte_stream

    @pdf_doc = PDF_DOCUMENT.new @pdf_reader, @pdf_writer
    @pdf_form = PDF_ACRO_FORM.getAcroForm(@pdf_doc, true)
    @form_fields = @pdf_form.getFormFields
  rescue StandardError => e
    raise "#{e.message} (input file may be corrupt, incompatible, or may not have any forms)"
  end
end

jaehocho avatar Mar 12 '21 06:03 jaehocho

I use Passenger on Heroku deploy. I found that passenger uses 'smart' thread spawning by default. I switched to 'direct' method and the problem went away. Smart spawning copies a thread to create a new one.

Passengers document indicates that it can create file descriptor sharing which can cause issues. I am guessing the shared file descriptors for the jar file somehow creates a deadlock.

https://www.phusionpassenger.com/library/indepth/ruby/spawn_methods/#unintentional-file-descriptor-sharing

Updated my Profile from:

web: bundle exec passenger start -p $PORT --max-pool-size 6

To:

web: bundle exec passenger start -p $PORT --max-pool-size 6 --spawn-method direct

jaehocho avatar Mar 12 '21 18:03 jaehocho

I am not sure why this is closed, because the error still exist with puma on heroku. Would it be helpful to get someone from puma gem into this thread? @jaehocho seem to have it fixed by a config for passenger. Maybe there is something similar for puma?

simonfranzen avatar Jul 17 '21 19:07 simonfranzen

Also having issues. Heroku and puma. It also hangs locally with spring. Using 0.9.2. Any ideas?

DanAndreasson avatar Aug 18 '21 09:08 DanAndreasson

@DanAndreasson Please check out the README.md for the latest list of known issues (I don't think spring is an issue any more) and for how to deploy on Heroku. Also, you could not have been using version 0.9.2 on August 18, because it did not come out until November 30. Please actually try version 0.9.2.

@simonfranzen Is it the latest version that keeps hanging? Version 0.9.2?

vkononov avatar Dec 02 '21 03:12 vkononov