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

FFI fails when required under rack #1108

Closed
ayoshi opened this issue Sep 2, 2016 · 4 comments
Closed

FFI fails when required under rack #1108

ayoshi opened this issue Sep 2, 2016 · 4 comments

Comments

@ayoshi
Copy link

ayoshi commented Sep 2, 2016

I have created a simple test app:

#\ -p 9292

require "ffi"

run ->(env) { [200, {"Content-Type" => "text/html"}, ["Hello World!"]] }

Running it fails:

root@b6335697b39b:/app# rackup -E none -o 0.0.0.0 -d -s thin test_ffi2.ru
"thin"
Exception `LoadError' at /usr/local/bundle/gems/ffi-1.9.14/lib/ffi.rb:4 - cannot load such file -- 2.2/ffi_c
#<Proc:0x005627e377fa68@/app/test_ffi2.ru:5 (lambda)>
#<Proc:0x005627e377fa68@/app/test_ffi2.ru:5 (lambda)>
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 0.0.0.0:9292, CTRL+C to stop

The same code runs with regular ruby with no problem

ruby -e 'require "ffi"'

Gives out no errors, the more complicated code works too:

require "ffi"

puts "libc => #{FFI::Library::LIBC}"
puts FFI::Platform
ffi_lib(FFI::Platform::LIBC)
puts "successfully loaded: #{ffi_libraries}"
root@b6335697b39b:/app# ruby  test_ffi.rb
libc => libc.so.6
successfully loaded: [#<FFI::DynamicLibrary:0x00564f0c7481d0 @name="libc.so.6">]

I've been pulling my hair out for 3 straight days. The real code inside handlers uses FFI several layers deeper, and of course it fails.

I'm running the tests under the official ruby:2.2.4 docker image.

Versions:

ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
ffi (1.9.14)
rack (1.6.4)
rack-cors (0.4.0)
rack-mini-profiler (0.10.1)
rack-protection (1.5.3)
rack-test (0.6.3)

@ayoshi
Copy link
Author

ayoshi commented Sep 2, 2016

Oh, I forgot to mention: running under rack-2 and thin 1.7.0 fails too:

root@b6335697b39b:/app# rackup -E none -o 0.0.0.0 -d -s thin test_ffi2.ru
"thin"
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- ffi
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- 2.2/ffi_c
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:135 - cannot load such file -- 2.2/ffi_c
#<Proc:0x00562dffca4170@/app/test_ffi2.ru:5 (lambda)>
#<Proc:0x00562dffca4170@/app/test_ffi2.ru:5 (lambda)>
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- thin
Exception `LoadError' at /usr/local/lib/ruby/2.2.0/resolv.rb:168 - LoadError
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on 0.0.0.0:9292, CTRL+C to stop

@ayoshi
Copy link
Author

ayoshi commented Sep 3, 2016

I had also performed an experiment installing ruby with Rvm on a standard Ubuntu image and hit the same errors.

@dillonwelch
Copy link
Contributor

@ayoshi there's been a lot of version changes in ruby, rack, etc since you reported this issue. Would you be able to use the latest version of the gems and see if this is still a problem?

@jeremyevans
Copy link
Contributor

The example given here isn't failing, it's simply printing exceptions because it is run in debug mode. You get the same errors when requiring directly in debug mode:

$ ruby -d -e 'require "ffi"'
Exception `LoadError' at /usr/local/lib/ruby/2.6/rubygems.rb:1375 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/local/lib/ruby/2.6/rubygems.rb:1384 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /usr/local/lib/ruby/2.6/rubygems/core_ext/kernel_require.rb:54 - cannot load such file -- ffi
Exception `LoadError' at /usr/local/lib/ruby/2.6/rubygems/core_ext/kernel_require.rb:54 - cannot load such file -- 2.6/ffi_c
Exception `LoadError' at /usr/local/lib/ruby/2.6/rubygems/core_ext/kernel_require.rb:132 - cannot load such file -- 2.6/ffi_c

Even if the output given, you can see the webserver still starts up and is listening:

Maximum connections set to 1024
Listening on 0.0.0.0:9292, CTRL+C to stop

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

3 participants