Skip to content

Commit

Permalink
[Shellout::Unix] Progressive select timeout [chef#245]
Browse files Browse the repository at this point in the history
This intends to strike a balance between quick and longer-running shellouts

Signed-off-by: David Crosby <[email protected]>
  • Loading branch information
dafyddcrosby committed Nov 12, 2024
1 parent bcdcd64 commit 594d1fe
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/mixlib/shellout/unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ def run_command

write_to_child_stdin

select_timeout = 0.001 # 1 millisecond

until @status
ready_buffers = attempt_buffer_read
ready_buffers = attempt_buffer_read(select_timeout)
unless ready_buffers
@execution_time += READ_WAIT_TIME
@execution_time += select_timeout

# 1.3 multiplier is so we get ~10 selects before we hit the 0.01 threshold
select_timeout *= 1.3 unless select_timeout > READ_WAIT_TIME
if @execution_time >= timeout && !@result
# kill the bad proccess
reap_errant_child
Expand Down Expand Up @@ -265,8 +270,8 @@ def write_to_child_stdin
child_stdin.close # Kick things off
end

def attempt_buffer_read
ready = IO.select(open_pipes, nil, nil, READ_WAIT_TIME)
def attempt_buffer_read(select_timeout = READ_WAIT_TIME)
ready = IO.select(open_pipes, nil, nil, select_timeout)
if ready
read_stdout_to_buffer if ready.first.include?(child_stdout)
read_stderr_to_buffer if ready.first.include?(child_stderr)
Expand Down

0 comments on commit 594d1fe

Please sign in to comment.