wicked_pdf: Thread puma threadpool terminated with exception machine stack overflow in critical region (fatal)

Issue description

Our CI server is having a problem with the recent major bump to 2.0. Locally we are fine and pdf’s work. If I downgrade to 1.4.0 our CI is fine.

Seems this was also an issue in the past: https://stackoverflow.com/questions/55280153/machine-stack-overflow-in-critical-region-fatal https://github.com/mileszs/wicked_pdf/issues/810

Randomized with seed 34635
Capybara starting Puma...
* Version 4.3.3 , codename: Mysterious Traveller
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:34469
#<Thread:0x0000561dc0601600@puma threadpool 001@/home/circleci/project/vendor/bundle/ruby/2.6.0/gems/puma-4.3.3/lib/puma/thread_pool.rb:89 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
/home/circleci/project/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/urlmap.rb:58:in `each': machine stack overflow in critical region (fatal)

https://github.com/puma/puma/blob/master/lib/puma/thread_pool.rb#L89 https://github.com/rack/rack/blob/master/lib/rack/urlmap.rb#L58

Expected or desired behavior

CI runs and passes

System specifications

wicked_pdf 2.0.1 wkhtmltopdf-binary-edge 0.12.4.0 because of https://github.com/pallymore/wkhtmltopdf-binary-edge/issues/15 and extra build config just to get it to work so we locked it Ubuntu 16.04 ruby 2.6.5 rails 6.0.2.1

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 23 (7 by maintainers)

Most upvoted comments

@Jeremie1707 I tried to quickly setup an app to reproduce this, and was not able to. I looked through the commits of rails_admin and see they recently made some updates to improve compatibility with the zeitwerk loader, so maybe it’s better now? You could try upgrading rails_admin and remotipart with:

bundle update rails_admin remotipart

And try again.

Another thing that might help and be minimally invasive is to defer requiring wicked_pdf until railties are booted, and your app initializers run. You can do this by editing Gemfile like this:

gem 'wicked_pdf', require: false

Then requiring wicked_pdf before it’s needed in the initializer:

require 'wicked_pdf'
WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}

Then only in the controllers it’s needed, add the PDF helpers:

class MyController < ApplicationController
  prepend WickedPdf::PdfHelper
  include WickedPdf::WickedPdfHelper::Assets

  def show
  end
end

Or, you can use @darrenterhune 's fork by just changing out your Gemfile

gem 'wicked_pdf', git: 'https://github.com/darrenterhune/wicked_pdf'

Please let me know what you end up doing and what worked or not.

Ok @unixmonkey I had some more time this avo to debug this. I forked this gem and made this change https://github.com/darrenterhune/wicked_pdf/commit/ccc861596dcd8e43e5243a79b8658cf7c3c9b4e0 and it’s now working and passing CI. I just wanted to make sure this comment was true https://github.com/mileszs/wicked_pdf/pull/869/files#r386040878

I also found this where some people are saying having ActiveSupport.on_load ran in multiple gems causes them issues https://github.com/rails/rails/issues/27013 which might be a problem (but I have no idea why) because remotipart also does this https://github.com/JangoSteve/remotipart/blob/master/lib/remotipart/rails/railtie.rb#L33-L36

We just need to 🔪 rails_admin but we are still months off from that and I suspect others will also have this issue.

This is no longer an issue since v2.6.0 was released back in May.

I’ve just removed this from my Gemfile:

# Tracking master to resolve: https://github.com/mileszs/wicked_pdf/issues/891
gem "wicked_pdf", github: "mileszs/wicked_pdf", branch: "master"

and upgraded to version v2.6.3.

Issue appears resolved with master branch 5cee578699fe3e5015eb7d76b604a0c121266018

At least CI is happy, I have not test deployed but should be alright.

@feliperaul the same thing really weird, thanks for suggestion

@almokhtarbr Nope, and I can’t even reproduce it, it’s totally random (every once 15 days for us).

For now I have switched to PDFKit, the APIs are very similar.

Does anyone in this thread can reliably reproduce this bug?

I’m also facing it, but only randomly.

Nate Berkopec, a Puma maintainer, is looking into this on https://github.com/puma/puma/issues/2552, but he also can’t reproduce the “fatal - machine stack overflow in critical region” error.

Please report in that issue if you can help.

Yep. Thanks for confirming that. I’m working on a replacement system that avoids any kind of conflict, but I suspect that won’t be released for a while either. You might be better off using your fork or monkey-patching the initializer as a no-op, and including/prepending in the controllers you need it in until then.