Skip to content

Commit

Permalink
Fixes #35637 - Make ProcessManager properly detect the child exited
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Nov 11, 2022
1 parent 62c79cf commit 7f81b79
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/smart_proxy_dynflow/process_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ def process(timeout: nil)
return
end

# Even though the FDs are still open, the child might have exited already
pid, status = Process.waitpid2(@pid, Process::WNOHANG)
timeout = 1 if pid

ready_readers, ready_writers = IO.select(readers, writers, nil, timeout)
(ready_readers || []).each(&:read_available!)
(ready_writers || []).each(&:write_available!)

finish(status) if pid
end

# Sets block to be executed each time data is read from child process' standard output
Expand Down Expand Up @@ -156,11 +162,13 @@ def close
# Makes the process manager finish its run, closing opened FDs and reaping the child process
#
# @return [void]
def finish
def finish(status = nil)
close
if @pid != -1 && !done?
if status.nil? && @pid != -1 && !done?
_pid, status = Process.wait2(@pid)
@status = status.exitstatus
elsif status
@status = status.exitstatus
end
end
end
Expand Down

0 comments on commit 7f81b79

Please sign in to comment.