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

Adding wicked_pdf leads to fatal error on any render #876

Open
Zeouterlimits opened this issue Jan 2, 2020 · 11 comments
Open

Adding wicked_pdf leads to fatal error on any render #876

Zeouterlimits opened this issue Jan 2, 2020 · 11 comments

Comments

@Zeouterlimits
Copy link

Issue description

Added wicked_pdf + wkhtmltopdf-binary to gemfile of existing spa project
Generated wicked initializer with default config
Startup application
Try to render any page (not ones that are invoking wicked pdf):

[a7a7e671-2c8c-4e2a-8274-aadef48292b2]
[a7a7e671-2c8c-4e2a-8274-aadef48292b2] FrozenError (can't modify frozen fatal):
[a7a7e671-2c8c-4e2a-8274-aadef48292b2]

Expected or desired behavior

No error occuring?

System specifications

wicked_pdf gem version (output of cat Gemfile.lock | grep wicked_pdf):

cat Gemfile.lock | grep wicked_pdf
    wicked_pdf (1.4.0)
  wicked_pdf

wkhtmltopdf version (output of wkhtmltopdf --version):

bundle exec wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)

whtmltopdf provider gem and version if one is used:

cat Gemfile.lock | grep wkhtmltopdf
    wkhtmltopdf-binary (0.12.5)
  wkhtmltopdf-binary

platform/distribution and version (e.g. Windows 10 / Ubuntu 16.04 / Heroku cedar):
Mac OS X Mojave 10.14.6

@unixmonkey
Copy link
Collaborator

When you say this is an SPA, do you mean that this is Rails running in API mode (no view rendering). If so, this thread has some tips for that.

What version of Ruby and Rails are you running?

@Zeouterlimits
Copy link
Author

No, it does have simplistic view rendering, in which we wrap react pages.

ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
bundle exec rails -v
Rails 6.0.0

@unixmonkey
Copy link
Collaborator

Can you try and point your Gemfile at the master branch and see if that helps? I very recently merged a Rails 6 comparatively PR, but haven’t released it yet.

@Zeouterlimits
Copy link
Author

Zeouterlimits commented Jan 3, 2020

Gave it a go, unfortunately I get the same fatal FrozenError.
Tried to increase my log level to debug but no futher info exposed.

While trying to research it, I did find someone else had this issue with the gem: https://stackoverflow.com/questions/55301110/frozen-error-when-trying-to-run-rails-application

Perhaps a deprecation error failing somewhat silently: rails/rails#37088 (not released yet I think)

@unixmonkey
Copy link
Collaborator

Thanks for that extra context. The comment that this is being raised as the result of a SystemStackError seems like a decent explanation. This gem has some incompatibilities with other gems that try to do similar thing by either prepending or alias_method_chaining of render. I intend to allow you to disable this behavior eventually.

Here are some threads that may help you determine what gem could be interfering, and some tips to work around this:
https://github.com/mileszs/wicked_pdf/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+SystemStackError

Let me know how it goes. If you keep having trouble, I'm sure I can help you out (probably with a monkeypatch or something), just let me know.

@summera
Copy link

summera commented Jan 17, 2020

@unixmonkey I am also having this same issue. On my machine I get a FrozenError: can't modify frozen fatal and my teammate is getting an interpreter crash. We noticed that the issue happened when ActiveSupport.on_load was introduced and were able to work around this by monkey patching wicked_pdf railtie, completely removing that code, and manually including the helpers in controllers and view helpers where needed. Specifically, I think ActionController::Base.send :prepend, PdfHelper is causing it for us because removing that line makes it so that FrozenError is not thrown. Any idea as to what's going on?

@bo-oz
Copy link

bo-oz commented Feb 24, 2020

I had the same when including gem 'wicked_pdf' to my Rails 5 application. It seems the latest version of Wicked PDF depends on Rails 6, could this be a similar problem?

@unixmonkey
Copy link
Collaborator

@bo-oz I don't think Rails 5 compatibility has anything to do with your issue. I've tested with Rails 5 and the current version. I have seen incompatibility with other gems that also override render, like the "remotipart" gem.

If this is your issue, there are some suggestions in #650 that may help you track it down.

spdawson added a commit to spdawson/view_component-frozen-error that referenced this issue Mar 24, 2020
Visiting the application root now results in the following error.

3: from actionview-6.0.2.2/lib/action_view/renderer/template_renderer.rb:59:in `block (2 levels) in render_template'
2: from actionview-6.0.2.2/lib/action_view/template.rb:182:in `render'
1: from actionview-6.0.2.2/lib/action_view/template.rb:188:in `rescue in render'

actionview-6.0.2.2/lib/action_view/template.rb:355:in `handle_render_error': can't modify frozen fatal: #<fatal: exception reentered> (ActionView::Template::Error)

Possibly related: mileszs/wicked_pdf#876
@gerardo-navarro
Copy link

Hi Guys, any update on this?

@krtschmr
Copy link

krtschmr commented Apr 7, 2021

same for us 🤷🏿

it's because we override def render of application controller

# def render(*args)
 #   response.set_header('Original-User', User.find(session[:original_user_id]).name) if session[:original_user_id]
 #   super
 # end

if i comment it, it works. if i use my override, it's an infinity loop

@wgirhad
Copy link

wgirhad commented Apr 4, 2023

Hi there, I was facing this exact same problem on version 1.4.0.
Upgrading to 2.6.3 solved the problem for me.

I've found out that when overriding the render method caused WickedPdf::PdfHelper to loop back to itself on this file lib/wicked_pdf/pdf_helper.rb:46

method(:render).super_method.call(options, *args, &block)

Anyway, here we are using Rails 6.1 with Ruby 2.7

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