diff --git a/lib/fluent/plugin/in_exec.rb b/lib/fluent/plugin/in_exec.rb index c285136604..e435b8f337 100644 --- a/lib/fluent/plugin/in_exec.rb +++ b/lib/fluent/plugin/in_exec.rb @@ -95,6 +95,7 @@ def run(io) else @parser.parse(io.read, &method(:on_record)) end + io.close if io.eof? end def on_record(time, record) diff --git a/test/plugin/test_in_exec.rb b/test/plugin/test_in_exec.rb index cbce44313b..c52d39b347 100644 --- a/test/plugin/test_in_exec.rb +++ b/test/plugin/test_in_exec.rb @@ -258,4 +258,14 @@ def create_driver(conf) assert_match(/LoadError/, event[2]['message']) end end + + test 'ensure not leaking file descriptor' do + omit "/proc/PID is not available on Windows" if Fluent.windows? + d = create_driver JSON_CONFIG_COMPAT + before_fd_count = Dir.glob("/proc/#{$$}/fd/*").length + d.run(expect_records: 10, timeout: 10) + after_fd_count = Dir.glob("/proc/#{$$}/fd/*").length + + assert{ before_fd_count == after_fd_count } + end end