Skip to content

Commit 4005f73

Browse files
committed
Ensure bash shell executions close file descriptors
Currently Bolt::Shell::Bash will leaves open file descriptors at the conclusion of execute(). The file descriptions do fall out of scope at the conclusion of the execute() method and the Ruby GC eventually closes them. However, on a very busy Bolt invocation with lots of short-lived Tasks or a number of Tasks running in parallel (e.g. via background()) the number of open FDs before garbage collection can get moderately high, hitting problems on systems with low file descriptor limits. !bug * **Explicitly close Bolt::Shell::Bash file descriptors** Ensure file descriptors in Bolt::Shell::Bash are explicitly closed, helping to alleviate the chance of hitting file descriptor limits on systems with low defaults (e.g. Mac OS).
1 parent 42ec31c commit 4005f73

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/bolt/shell/bash.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,10 @@ def execute(command, sudoable: false, **options)
470470
result_output.merged_output << to_print
471471
}
472472
rescue Errno::EAGAIN, EOFError
473+
ensure
474+
stream.close
473475
end
476+
inp.close
474477
result_output.stdout << read_streams[out]
475478
result_output.stderr << read_streams[err]
476479
result_output.exit_code = t.value.respond_to?(:exitstatus) ? t.value.exitstatus : t.value
@@ -490,7 +493,7 @@ def execute(command, sudoable: false, **options)
490493
result_output
491494
rescue StandardError
492495
# Ensure we close stdin and kill the child process
493-
inp&.close
496+
inp.close unless inp.nil? || inp.closed?
494497
t&.terminate if t&.alive?
495498
@logger.trace { "Command aborted" }
496499
raise

0 commit comments

Comments
 (0)