Skip to content

Commit 3a19c89

Browse files
committed
Do not allow finalization to close non-autoclose streams.
JRuby 9k includes a stricter port of MRI's low-level IO behavior, and as a result normal termination of a JRuby runtime will shut down all streams still active. This includes stdio streams, and bugs like #1917 show the problem with that: there may still be non-daemon JVM threads running that need those streams. MRI also includes the notion of a "prep" stream, which is one that should not be autoclosed on GC. We have this flag, and honored the behavior in MRI that prevents the underlying file descriptor from being closed, but given that we need a working IO object I think expanding that protection is warranted. So this patch causes both GC-initiated and tearDown-initiated IO finalization to do *nothing* if the stream is set to not autoclose. This won't leak any objects, since GC will still clean up the IO object, and it fixes issues with threads living past the end of the script. Fixes #1917.
1 parent 745848c commit 3a19c89

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ public void finalize(Ruby runtime, OpenFile fptr, boolean noraise) {
829829
};
830830

831831
public void finalize() {
832-
if (fd != null) finalize(runtime.getCurrentContext(), true);
832+
if (fd != null && isAutoclose()) finalize(runtime.getCurrentContext(), true);
833833
}
834834

835835
public void finalize(ThreadContext context, boolean noraise) {

0 commit comments

Comments
 (0)