Skip to content

Commit

Permalink
Do not allow finalization to close non-autoclose streams.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
headius committed Jan 12, 2015
1 parent 745848c commit 3a19c89
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/io/OpenFile.java
Expand Up @@ -829,7 +829,7 @@ public void finalize(Ruby runtime, OpenFile fptr, boolean noraise) {
};

public void finalize() {
if (fd != null) finalize(runtime.getCurrentContext(), true);
if (fd != null && isAutoclose()) finalize(runtime.getCurrentContext(), true);
}

public void finalize(ThreadContext context, boolean noraise) {
Expand Down

0 comments on commit 3a19c89

Please sign in to comment.