Guest User

Untitled

a guest
Jan 22nd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. diff --git a/src/org/jruby/util/io/OpenFile.java b/src/org/jruby/util/io/OpenFile.java
  2. index b9c2700..ec4c96e 100644
  3. --- a/src/org/jruby/util/io/OpenFile.java
  4. +++ b/src/org/jruby/util/io/OpenFile.java
  5. @@ -301,16 +301,25 @@ public class OpenFile {
  6. try {
  7. ChannelDescriptor main = null;
  8. ChannelDescriptor pipe = null;
  9. +
  10. + // Recent JDKs shut down streams in the parent when child
  11. + // terminates, so we can't trust that they'll be open for our
  12. + // close. Check for that.
  13. +
  14. + boolean isProcess = process != null;
  15.  
  16. synchronized (this) {
  17. Stream ps = pipeStream;
  18. if (ps != null) {
  19. pipe = ps.getDescriptor();
  20.  
  21. - // TODO: Ruby logic is somewhat more complicated here, see comments after
  22. try {
  23. - ps.fflush();
  24. - ps.fclose();
  25. + // check for closed channel due to child exit
  26. + if (isProcess && ps.getChannel().isOpen()
  27. + || !isProcess) {
  28. + ps.fflush();
  29. + ps.fclose();
  30. + }
  31. } finally {
  32. // make sure the pipe stream is set to null
  33. pipeStream = null;
  34. @@ -321,10 +330,14 @@ public class OpenFile {
  35. // TODO: Ruby logic is somewhat more complicated here, see comments after
  36. main = ms.getDescriptor();
  37. try {
  38. - if (pipe == null && isWriteBuffered()) {
  39. - ms.fflush();
  40. + // check for closed channel due to child exit
  41. + if (isProcess && ms.getChannel().isOpen()
  42. + || !isProcess) {
  43. + if (pipe == null && isWriteBuffered()) {
  44. + ms.fflush();
  45. + }
  46. + ms.fclose();
  47. }
  48. - ms.fclose();
  49. } catch (BadDescriptorException bde) {
  50. if (main == pipe) {
  51. } else {
Add Comment
Please, Sign In to add comment