We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
headius
Learn more about funding links in repositories.
Report abuse
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
I have some logging code that looks like this:
def log(line) io.puts(line) io.fsync end
This code is called from multiple threads.
In production, I've noticed lines that there are lines that look like this: "#{line1}#{line2}\n\n".
"#{line1}#{line2}\n\n"
I looked into it, and it looks like puts might have a race condition between writing the line and writing the subsequent newline. See
puts
jruby/core/src/main/java/org/jruby/RubyIO.java
Line 2526 in 0be4796
Some repro code:
require 'thread' 8.times.map do Thread.new do 1000.times do $stdout.puts "line" $stdout.fsync end end end.map(&:join)
To test:
ruby puts.rb | grep lineline
/cc @cheald
The text was updated successfully, but these errors were encountered:
MRI does exactly the same thing: https://github.com/ruby/ruby/blob/trunk/io.c#L7102
You've always had to do io.write "line\n" to avoid it.
io.write "line\n"
Sorry, something went wrong.
As Freaky points out, MRI does indeed exhibit this interleaving behavior.
That said, I would argue the behavior is surprising and probably should be fixed in MRI, too!
No branches or pull requests
I have some logging code that looks like this:
This code is called from multiple threads.
In production, I've noticed lines that there are lines that look like this:
"#{line1}#{line2}\n\n"
.I looked into it, and it looks like
puts
might have a race condition between writing the line and writing the subsequent newline. Seejruby/core/src/main/java/org/jruby/RubyIO.java
Line 2526 in 0be4796
Some repro code:
To test:
ruby puts.rb | grep lineline
/cc @cheald
The text was updated successfully, but these errors were encountered: