Skip to content

Commit

Permalink
Reorder close cleanup before thread wakeups.
Browse files Browse the repository at this point in the history
Fixes a race in test_io.rb:test_race_closed_stream from MRI.

See https://bugs.ruby-lang.org/issues/13158
headius committed Mar 15, 2018

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent 8f7385d commit 9cd2bae
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -2049,6 +2049,8 @@ protected IRubyObject rbIoClose(Ruby runtime) {
if (fptr == null) return runtime.getNil();
if (fptr.fd() == null) return runtime.getNil();

fptr.finalizeFlush(context, false);

// interrupt waiting threads
fptr.interruptBlockingThreads(context);
try {
@@ -2057,6 +2059,7 @@ protected IRubyObject rbIoClose(Ruby runtime) {
} finally {
fptr.lock();
}

fptr.cleanup(runtime, false);

if (fptr.getProcess() != null) {
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/util/io/OpenFile.java
Original file line number Diff line number Diff line change
@@ -838,6 +838,10 @@ public void finalize() {
}

public void finalize(ThreadContext context, boolean noraise) {
finalizeFlush(context, noraise);
}

public void finalizeFlush(ThreadContext context, boolean noraise) {
IRubyObject err = runtime.getNil();
ChannelFD fd = this.fd();
Closeable stdio_file = this.stdio_file;

0 comments on commit 9cd2bae

Please sign in to comment.