Skip to content

Commit

Permalink
Ensure bash shell executions close file descriptors
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
seanmil committed Jun 26, 2024
1 parent 42ec31c commit 4005f73
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/bolt/shell/bash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ def execute(command, sudoable: false, **options)
result_output.merged_output << to_print
}
rescue Errno::EAGAIN, EOFError
ensure
stream.close
end
inp.close
result_output.stdout << read_streams[out]
result_output.stderr << read_streams[err]
result_output.exit_code = t.value.respond_to?(:exitstatus) ? t.value.exitstatus : t.value
Expand All @@ -490,7 +493,7 @@ def execute(command, sudoable: false, **options)
result_output
rescue StandardError
# Ensure we close stdin and kill the child process
inp&.close
inp.close unless inp.nil? || inp.closed?
t&.terminate if t&.alive?
@logger.trace { "Command aborted" }
raise
Expand Down

0 comments on commit 4005f73

Please sign in to comment.