Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.