File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,11 @@ def reopen
39
39
@mutex . synchronize {
40
40
if defined? @io && @io
41
41
flush
42
- @io . close rescue nil
42
+ # JRuby will close the underlying file descriptor, so we don't want to
43
+ # do that even though this is a copy of STDOUT / STDERR
44
+ if !defined? ( JRUBY_VERSION )
45
+ @io . close rescue nil
46
+ end
43
47
end
44
48
@io = open_fd
45
49
}
Original file line number Diff line number Diff line change @@ -48,9 +48,16 @@ def close( *args )
48
48
super
49
49
50
50
io , @io = @io , nil
51
- unless [ STDIN , STDERR , STDOUT ] . include? ( io )
52
- io . send ( @close_method ) if @close_method && io . respond_to? ( @close_method )
51
+
52
+ # JRuby will always close the underlying file descriptor, so we need to
53
+ # check the FD number and not just the Ruby object ID
54
+ close_io = if defined? ( JRUBY_VERSION )
55
+ ![ STDIN . fileno , STDERR . fileno , STDOUT . fileno ] . include? ( io . fileno )
56
+ else
57
+ ![ STDIN , STDERR , STDOUT ] . include? ( io )
53
58
end
59
+
60
+ io . send ( @close_method ) if close_io && @close_method && io . respond_to? ( @close_method )
54
61
rescue IOError
55
62
ensure
56
63
return self
You can’t perform that action at this time.
0 commit comments