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

Gem fails to initialize when mounted in a read-only filesystem #189

Closed
ben opened this issue Apr 15, 2021 · 5 comments
Closed

Gem fails to initialize when mounted in a read-only filesystem #189

ben opened this issue Apr 15, 2021 · 5 comments

Comments

@ben
Copy link

ben commented Apr 15, 2021

I'm running a Rails app in Kubernetes, and the root filesystem is mounted as read-only. On startup using 0.13.0, I get an exception with this as the first few lines of the stacktrace:

Read-only file system @ rb_sysopen - /app/.const_generator20210415-16-174j4gr
/usr/lib/ruby/2.7.0/tempfile.rb:129:in `initialize'
/usr/lib/ruby/2.7.0/tempfile.rb:129:in `open'
/usr/lib/ruby/2.7.0/tempfile.rb:129:in `block in initialize'
/usr/lib/ruby/2.7.0/tmpdir.rb:129:in `create'
/usr/lib/ruby/2.7.0/tempfile.rb:127:in `initialize'
/usr/lib/ruby/2.7.0/tempfile.rb:287:in `new'
/usr/lib/ruby/2.7.0/tempfile.rb:287:in `open'
/usr/bundle/ruby/2.7.0/gems/ffi-1.15.0/lib/ffi/tools/const_generator.rb:110:in `calculate'
/usr/bundle/ruby/2.7.0/gems/ffi-1.15.0/lib/ffi/tools/const_generator.rb:49:in `initialize'
/usr/bundle/ruby/2.7.0/gems/ethon-0.13.0/lib/ethon/libc.rb:17:in `new'
/usr/bundle/ruby/2.7.0/gems/ethon-0.13.0/lib/ethon/libc.rb:17:in `<module:Libc>'
/usr/bundle/ruby/2.7.0/gems/ethon-0.13.0/lib/ethon/libc.rb:7:in `<module:Ethon>'
/usr/bundle/ruby/2.7.0/gems/ethon-0.13.0/lib/ethon/libc.rb:2:in `<top (required)>'

Looks like between 0.12.0 and 0.13.0 there was a change that introduced the use of FFI::ConstGenerator, whose default initializer sets it up to write to the current directory.

Could ethon initialize the ConstGenerator to use ENV['TMPDIR'] || '/tmp' instead of the default?

@Kjarrigan
Copy link
Member

Hm. Not sure if this is possible. Because the line that crashed is https://github.com/ffi/ffi/blob/master/lib/ffi/tools/const_generator.rb#L110 and Tempfile.opens second param (which is not set in FFI) is used to change the temp_dir

But in https://github.com/ffi/ffi/blob/master/lib/ffi/tools/const_generator.rb#L108 they already use Dir.tmpdir for the binary so I think you could open a FFI-Pullrequest to use it for Tempfile.open too

@ben
Copy link
Author

ben commented Apr 16, 2021

The line that opens the file uses "#{@prefix}.const_generator" as the filename. @prefix is set in the initializer. So if ethon were to do this at the callsite:

fcg = FFI::ConstGenerator.new(ENV['TMPDIR'] || '/tmp') do |gen|

…I believe that would solve this issue.

@tagliala
Copy link
Contributor

tagliala commented Apr 16, 2021

Hi, I had a similar issue because FFI was attempting to execute a file in the tmp dir

Any chance to TL;DR what that binary does?

edit TL;DR: gets the value of _SC_OPEN_MAX

@Kjarrigan
Copy link
Member

@ben I don't think so¹ but feel free to try it out. After all this is Ruby and you can change all the code you want.

¹The prefix of a tempfile only influences the filename as you can see in the docs I linked.

@Kjarrigan
Copy link
Member

Should be solved in the next version. See #185

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