Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/org/jruby/util/io/OpenFile.java b/src/org/jruby/util/io/OpenFile.java
- index b9c2700..ec4c96e 100644
- --- a/src/org/jruby/util/io/OpenFile.java
- +++ b/src/org/jruby/util/io/OpenFile.java
- @@ -301,16 +301,25 @@ public class OpenFile {
- try {
- ChannelDescriptor main = null;
- ChannelDescriptor pipe = null;
- +
- + // Recent JDKs shut down streams in the parent when child
- + // terminates, so we can't trust that they'll be open for our
- + // close. Check for that.
- +
- + boolean isProcess = process != null;
- synchronized (this) {
- Stream ps = pipeStream;
- if (ps != null) {
- pipe = ps.getDescriptor();
- - // TODO: Ruby logic is somewhat more complicated here, see comments after
- try {
- - ps.fflush();
- - ps.fclose();
- + // check for closed channel due to child exit
- + if (isProcess && ps.getChannel().isOpen()
- + || !isProcess) {
- + ps.fflush();
- + ps.fclose();
- + }
- } finally {
- // make sure the pipe stream is set to null
- pipeStream = null;
- @@ -321,10 +330,14 @@ public class OpenFile {
- // TODO: Ruby logic is somewhat more complicated here, see comments after
- main = ms.getDescriptor();
- try {
- - if (pipe == null && isWriteBuffered()) {
- - ms.fflush();
- + // check for closed channel due to child exit
- + if (isProcess && ms.getChannel().isOpen()
- + || !isProcess) {
- + if (pipe == null && isWriteBuffered()) {
- + ms.fflush();
- + }
- + ms.fclose();
- }
- - ms.fclose();
- } catch (BadDescriptorException bde) {
- if (main == pipe) {
- } else {
Add Comment
Please, Sign In to add comment