aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-12-05 15:40:05 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-12-05 15:40:05 -0800
commit6f9d97cdb5d085476092731fa193359d4e4e3eae (patch)
tree67bc3c8bb146343d29637ca3167e42be9f0c260f
parentea75eb6499da78589db6b93daea11994487a2e5c (diff)
parentffe99774bb0b64644dc419ba83d131218854d404 (diff)
downloadrails-6f9d97cdb5d085476092731fa193359d4e4e3eae.tar.gz
rails-6f9d97cdb5d085476092731fa193359d4e4e3eae.tar.bz2
rails-6f9d97cdb5d085476092731fa193359d4e4e3eae.zip
Merge pull request #12684 from mariovisic/fix_kernel_silence_stream_descriptor_leak
Fix issue with Kernel#silence_stream leaking file descriptors
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/lib/active_support/core_ext/kernel/reporting.rb1
-rw-r--r--activesupport/test/core_ext/kernel_test.rb16
3 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index ea4aaff610..d23b598144 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Fix file descriptor being leaked on each call to `Kernel.silence_stream`
+
+ *Mario Visic*
+
* Ensure `config.i18n.enforce_available_locales` is set before any other
configuration option.
diff --git a/activesupport/lib/active_support/core_ext/kernel/reporting.rb b/activesupport/lib/active_support/core_ext/kernel/reporting.rb
index df11737a6b..3b5e205244 100644
--- a/activesupport/lib/active_support/core_ext/kernel/reporting.rb
+++ b/activesupport/lib/active_support/core_ext/kernel/reporting.rb
@@ -48,6 +48,7 @@ module Kernel
yield
ensure
stream.reopen(old_stream)
+ old_stream.close
end
# Blocks and ignores any exception passed as argument if raised within the block.
diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb
index b8951de402..18b251173f 100644
--- a/activesupport/test/core_ext/kernel_test.rb
+++ b/activesupport/test/core_ext/kernel_test.rb
@@ -38,6 +38,22 @@ class KernelTest < ActiveSupport::TestCase
# Skip if we can't STDERR.tell
end
+ def test_silence_stream
+ old_stream_position = STDOUT.tell
+ silence_stream(STDOUT) { STDOUT.puts 'hello world' }
+ assert_equal old_stream_position, STDOUT.tell
+ rescue Errno::ESPIPE
+ # Skip if we can't stream.tell
+ end
+
+ def test_silence_stream_closes_file_descriptors
+ stream = StringIO.new
+ dup_stream = StringIO.new
+ stream.stubs(:dup).returns(dup_stream)
+ dup_stream.expects(:close)
+ silence_stream(stream) { stream.puts 'hello world' }
+ end
+
def test_quietly
old_stdout_position, old_stderr_position = STDOUT.tell, STDERR.tell
quietly do