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

rbtree collides with rmagick on aws linux #641

Closed
createmycookbook opened this issue Jan 14, 2021 · 8 comments
Closed

rbtree collides with rmagick on aws linux #641

createmycookbook opened this issue Jan 14, 2021 · 8 comments
Labels

Comments

@createmycookbook
Copy link

I get a segmentation fault when attempting to use rmagick if and only if airbrake has loaded. I have traced it down to the rbtree3 gem. To reproduce:

gem install rmagick
gem install rbtree3
require 'rbtree'
require 'rmagick'

::Magick::ImageList.new("somepdf.pdf") # seg fault and crashes the ruby interpreter

Not sure about how the extension is compiled here, but seems to be problematic.

@kyrylo
Copy link
Contributor

kyrylo commented Jan 15, 2021

Does this happen with rbtree as well (not rbtree3)?
What Ruby version are you using?

@kyrylo
Copy link
Contributor

kyrylo commented Jan 15, 2021

I cannot reproduce the segfault. When the file doesn't exist, I get:

Traceback (most recent call last):
        5: from foo.rb:6:in `<main>'
        4: from foo.rb:6:in `new'
        3: from /Users/kyrylo/.gem/ruby/2.7.1/gems/rmagick-4.1.2/lib/rmagick_internal.rb:1595:in `initialize'
        2: from /Users/kyrylo/.gem/ruby/2.7.1/gems/rmagick-4.1.2/lib/rmagick_internal.rb:1595:in `each'
        1: from /Users/kyrylo/.gem/ruby/2.7.1/gems/rmagick-4.1.2/lib/rmagick_internal.rb:1596:in `block in initialize'
/Users/kyrylo/.gem/ruby/2.7.1/gems/rmagick-4.1.2/lib/rmagick_internal.rb:1596:in `read': unable to open image 'somepdf.pdf': No such file or directory @ error/blob.c/OpenBlob/3537 (Magick::ImageMagickError)

When the file exists, the script exits with 0.

I am on Ruby 2.7.1, rmagick 4.1.2, rbtree3 0.6.0

@createmycookbook
Copy link
Author

Just reproduced it using a brand new elastic beanstalk passenger with ruby 2.6 running on Amazon Linux 64 bit. 2.12.2

with ruby 2.6.6, rmagick 4.1.2, rbtree3 0.6.0

I just created brand new environment to validate. Two things:

  1. It doesn't seem to happen on OSX, only Linux.
  2. You must reference a PDF with rmagick, not a jpg
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
[ec2-user@ip-10-154-232-242 ~]$ mkdir t
[ec2-user@ip-10-154-232-242 ~]$ cd t
[ec2-user@ip-10-154-232-242 t]$ sudo su
[root@ip-10-154-232-242 t]# gem install rbtree3
Fetching rbtree3-0.6.0.gem
Building native extensions. This could take a while...
Successfully installed rbtree3-0.6.0
Parsing documentation for rbtree3-0.6.0
Installing ri documentation for rbtree3-0.6.0
Done installing documentation for rbtree3 after 0 seconds
1 gem installed
[root@ip-10-154-232-242 t]# gem install rmagick
Fetching rmagick-4.1.2.gem
Building native extensions. This could take a while...
Successfully installed rmagick-4.1.2
Parsing documentation for rmagick-4.1.2
Installing ri documentation for rmagick-4.1.2
Done installing documentation for rmagick after 1 seconds
1 gem installed
[root@ip-10-154-232-242 t]# wget "http://www.africau.edu/images/default/sample.pdf"
--2021-01-15 16:22:02--  http://www.africau.edu/images/default/sample.pdf
Resolving www.africau.edu (www.africau.edu)... 104.21.63.175, 172.67.148.215, 2606:4700:3037::6815:3faf, ...
Connecting to www.africau.edu (www.africau.edu)|104.21.63.175|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3028 (3.0K) [application/pdf]
Saving to: ‘sample.pdf’

sample.pdf                                                     100%[===================================================================================================================================================>]   2.96K  --.-KB/s    in 0s      

2021-01-15 16:22:02 (250 MB/s) - ‘sample.pdf’ saved [3028/3028]

[root@ip-10-154-232-242 t]# ls
sample.pdf
[root@ip-10-154-232-242 t]# irb
irb(main):001:0> require 'rbtree'
=> true
irb(main):002:0> require 'rmagick'
=> true
irb(main):003:0> ::Magick::ImageList.new("sample.pdf")
/opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rmagick-4.1.2/lib/rmagick_internal.rb:1596: [BUG] Segmentation fault at 0x000000000000027c
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0026 p:---- s:0126 e:000125 CFUNC  :read
c:0025 p:0019 s:0121 e:000120 BLOCK  /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rmagick-4.1.2/lib/rmagick_internal.rb:1596 [FINISH]
c:0024 p:---- s:0117 e:000116 CFUNC  :each
c:0023 p:0015 s:0113 e:000112 METHOD /opt/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/rmagick-4.1.2/lib/rmagick_internal.rb:1595 [FINISH]
c:0022 p:---- s:0107 e:000106 CFUNC  :new
c:0021 p:0017 s:0102 e:000101 EVAL   (irb):3 [FINISH]
c:0020 p:---- s:0099 e:000098 CFUNC  :eval
c:0019 p:0021 s:0091 e:000090 METHOD /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/irb/workspace.rb:85

@kyrylo
Copy link
Contributor

kyrylo commented Jan 15, 2021

Thanks, so does this happen when using https://rubygems.org/gems/rbtree ?

@createmycookbook
Copy link
Author

It does. Happens with both of them.

@kyrylo
Copy link
Contributor

kyrylo commented Jan 15, 2021

Thanks for verifying this. So I'm reading your repro script but I don't see airbrake being required anywhere. In the issue description you say this happens only when airbrake is required. Can you update the script and show me where you require airbrake? Perhaps the order of the requires could matter.

I'm probably missing something but I don't see where airbrake-ruby comes into play and messes things up for you. rbtree3 is our dependency but since you report the issue with rbtree as well, this could be an issue with rbtree and/or rmagick.

@createmycookbook
Copy link
Author

It appears that rbtree3 was your fork of rbtree if I'm not mistaken. It is also a dependency that of course renders airbrake-ruby unusable to us which is why I mentioned it here.

You could generate the same error by require 'airbrake-ruby' instead of require 'rbtree'

It does appear that if you require 'rmagick' and reference a class from it before requiring 'rbtree' that you can in fact make it work. However, since airbrake monkey patches several core rails infrastructure classes, the only real workaround I have found is to put a require 'rmagick' ; ::Magick::ImageList.new("some.pdf") in the config/boot.rb.

Happy to move this over to rbtree and rmagick as well if you like, just thought you might want to be aware, and see if you had any ideas

@kyrylo
Copy link
Contributor

kyrylo commented Jan 25, 2021

rbtree3 is indeed my fork, and it is indeed a dependency of airbrake-ruby 🙂

The issue doesn't seem to be related specifically to airbrake-ruby, that's why I believe it should be moved to rbtree3 or rmagick. Since the error is being raised by rmagick, it seems like the rmagick repo is the most logical place for this bug report for now.

I am not an rmagick expert, so unfortunately I don't have enough knoweldge and time to dig into that. I am happy to assist, though. Hope this makes sense.

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

No branches or pull requests

2 participants