Skip to content

Commit 5da207b

Browse files
committed
[GR-16975] Rescue EPIPE when flushing STDOUT/STDERR in at_exit hook
* If the calling process closed the pipe, there is nothing to do.
1 parent 857d7fb commit 5da207b

File tree

1 file changed

+8
-2
lines changed
  • src/main/ruby/truffleruby/core

1 file changed

+8
-2
lines changed

src/main/ruby/truffleruby/core/post.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ def external_encoding
6060
STDERR.sync = true
6161

6262
# Always flush standard streams on exit
63-
Truffle::KernelOperations.at_exit true do
63+
Truffle::KernelOperations.at_exit(true) do
6464
STDOUT.flush
65+
rescue Errno::EPIPE
66+
# Could not write to STDOUT, the calling process closed the pipe
67+
nil
6568
end
66-
Truffle::KernelOperations.at_exit true do
69+
Truffle::KernelOperations.at_exit(true) do
6770
STDERR.flush
71+
rescue Errno::EPIPE
72+
# Could not write to STDERR, the calling process closed the pipe
73+
nil
6874
end
6975

7076
module Truffle

0 commit comments

Comments
 (0)