rposborne/wkhtmltopdf-heroku

PDF printing fails intermittently

abhishek77in opened this issue · 9 comments

ERROR MESSAGE:

MESSAGE command failed (exitstatus=139): /app/vendor/bundle/ruby/2.5.0/gems/wkhtmltopdf-heroku-2.12.4.0/bin/wkhtmltopdf-linux-amd64 --encoding UTF-8 --dpi 300 --margin-top 75.0 --margin-bottom 55.0 --header-html /app/tmp/LabReport-Mr.XYZ-14-02-2019\ header20190214-4-7ofe2a.html --footer-html /app/tmp/LabReport-Mr.XYZ-14-02-2019\ footer20190214-4-nf4kpo.html --disable-smart-shrinking - -

What does exitstatus 139 mean?

I've had that happen to me a couple of times as well.
Rebooting the workers usually solves it.

This probably should be reported to https://github.com/wkhtmltopdf/wkhtmltopdf though.

I happen to get this error everyday. I need to do some deeper analysis though, most of the times after the few attempts by sidekiq the PDF is printed but in some cases re-attempting the print does not work at all. I will add more when see the cases where it fails. We have user generated rich text content so that would be a reason. I am quite optimistic as not many people are facing this issue, although I need 100% guarantee when printing the PDFs for my application to work reliably.

Yea - this is an issue with wkhtmltopdf.

I suspect it is related to some HTML/CSS/SVG thing.
For me - this only happens when I try to create reports with pie-charts - if I remove the pie-chart page then it can generate thousands of PDFs without failing even once.
However - it seems to work for some other pie-charts (using the same HTML template) with slightly different content. I have yet to figure out what is actually causing them to fail randomly :/

Over 1.5 year now and issue persists. The PDF printing has always worked (with retries) for over a few lakh (more than ~5 lakh) PDFs with an avg. ~30 errors per day for printing on an ~5000 PDFs (about 1% error rate).

The line where error occurs suggests some issue with ruby - https://stackoverflow.com/questions/2164887/thread-safe-external-process-in-ruby-plus-checking-exitstatus

# $? is thread safe per
# http://stackoverflow.com/questions/2164887/thread-safe-external-process-in-ruby-plus-checking-exitstatus
raise "command failed (exitstatus=#{$?.exitstatus}): #{invoke}" if empty_result?(path, result) or !successful?($?)
return result

RuntimeError_in_labsmart-review-app-pr-1589_1

I do not have any complicated HTML content, it's just usual markup with p tags and table tags etc. I do use JS to render page no.s.

@pallymore Could xvfb-run be helpful in this case? - I am getting exitstatus=134 which is same as mentioned in this comment - barryvdh/laravel-snappy#122 (comment)

Hi @abhishek77in - sorry for the late response - could you try the latest version? (2.12.6.0)

again this is most likely an issue with wkhtmltopdf itself - not this gem.

@pallymore Hi, thanks for your response, as I dig in further I can see how this is an issue with wkthmltopdf itself. I have raised an issue in wkhtmltopdf project - wkhtmltopdf/wkhtmltopdf#4861

@pallymore Hi, I was able to resolve the issue, intermittent failures were due to tempfile getting garbage collected, more on this here - wkhtmltopdf/wkhtmltopdf#4861

Big thanks for keeping the gem updated. @pallymore :)

thanks for the update @abhishek77in - glad it's resolved 😄