Skip to content

Commit 9cd2bae

Browse files
committedMar 15, 2018
Reorder close cleanup before thread wakeups.
Fixes a race in test_io.rb:test_race_closed_stream from MRI. See https://bugs.ruby-lang.org/issues/13158
1 parent 8f7385d commit 9cd2bae

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/RubyIO.java

+3
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,8 @@ protected IRubyObject rbIoClose(Ruby runtime) {
20492049
if (fptr == null) return runtime.getNil();
20502050
if (fptr.fd() == null) return runtime.getNil();
20512051

2052+
fptr.finalizeFlush(context, false);
2053+
20522054
// interrupt waiting threads
20532055
fptr.interruptBlockingThreads(context);
20542056
try {
@@ -2057,6 +2059,7 @@ protected IRubyObject rbIoClose(Ruby runtime) {
20572059
} finally {
20582060
fptr.lock();
20592061
}
2062+
20602063
fptr.cleanup(runtime, false);
20612064

20622065
if (fptr.getProcess() != null) {

Diff for: ‎core/src/main/java/org/jruby/util/io/OpenFile.java

+4
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,10 @@ public void finalize() {
838838
}
839839

840840
public void finalize(ThreadContext context, boolean noraise) {
841+
finalizeFlush(context, noraise);
842+
}
843+
844+
public void finalizeFlush(ThreadContext context, boolean noraise) {
841845
IRubyObject err = runtime.getNil();
842846
ChannelFD fd = this.fd();
843847
Closeable stdio_file = this.stdio_file;

0 commit comments

Comments
 (0)
Please sign in to comment.