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

Odd sharing of files between forked processes #2430

Closed
alindeman opened this issue Jul 7, 2013 · 3 comments
Closed

Odd sharing of files between forked processes #2430

alindeman opened this issue Jul 7, 2013 · 3 comments

Comments

@alindeman
Copy link
Contributor

Consider:

require 'tempfile'

out = Tempfile.new("abc")

File.open("/tmp/hello.rb", "w") { |f| f << "File.open('#{out.path}', 'a') { |f| f << 'first!' }" }
pid = fork { exec(["./bin/rbx", "./bin/rbx"], "/tmp/hello.rb") }
Process.waitpid(pid)

File.open("/tmp/hello.rb", "w") { |f| f << "File.open('#{out.path}', 'a') { |f| f << 'second!' }" }
pid = fork { exec(["./bin/rbx", "./bin/rbx"], "/tmp/hello.rb") }
Process.waitpid(pid)

puts File.read(out.path) # => first!first!

first!second! is expected.

$ ruby -v
rubinius 2.0.0.rc1 (1.8.7 00f249f8 yyyy-mm-dd JI) [x86_64-apple-darwin12.4.0]

Also reproducable with RBXOPT=-X19

@dbussink
Copy link
Contributor

dbussink commented Jul 7, 2013

I've updated the issue with different paths to call rbx, since I was totally confused at first that this worked fine, but it was invoking MRI on my system, since ruby executes MRI here for me by default

@dbussink
Copy link
Contributor

dbussink commented Jul 7, 2013

Ok, this seems to have nothing to do with forking, but with a problem with our compiled code caching. If I do the following, it works correctly for me:

export RBXOPT=-Xcompiler.no_rbc

This basically disables caching compiled Ruby code. For some reason it doesn't see /tmp/hello.rb as being changed, so it runs the cached version the second time even through it's obviously not correct there since the script has changed.

@alindeman
Copy link
Contributor Author

Ok, this seems to have nothing to do with forking, but with a problem with our compiled code caching. If I do the following, it works correctly for me:

export RBXOPT=-Xcompiler.no_rbc

This basically disables caching compiled Ruby code. For some reason it doesn't see /tmp/hello.rb as being changed, so it runs the cached version the second time even through it's obviously not correct there since the script has changed.

Perfect, thanks for isolating it further. The bug manifested itself in some of my code that forked, so it's the example I was able to isolate.

What does Rubinius use to determine if code needs to be recompiled? Maybe it's related to timing if it's using something like file mtime.

pirj added a commit to rspec/rspec-core that referenced this issue Dec 15, 2020
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this issue Oct 19, 2021
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

2 participants