Merge pull request #11365 from Bo98/syscommand-queue
system_command: better handle race conditions when interrupting
This commit is contained in:
commit
2b9fd5460e
@ -200,23 +200,26 @@ class SystemCommand
|
|||||||
write_input_to(raw_stdin)
|
write_input_to(raw_stdin)
|
||||||
raw_stdin.close_write
|
raw_stdin.close_write
|
||||||
|
|
||||||
|
thread_ready_queue = Queue.new
|
||||||
|
thread_done_queue = Queue.new
|
||||||
line_thread = Thread.new do
|
line_thread = Thread.new do
|
||||||
Thread.handle_interrupt(ProcessTerminatedInterrupt => :never) do
|
Thread.handle_interrupt(ProcessTerminatedInterrupt => :never) do
|
||||||
|
thread_ready_queue << true
|
||||||
each_line_from [raw_stdout, raw_stderr], &block
|
each_line_from [raw_stdout, raw_stderr], &block
|
||||||
end
|
end
|
||||||
# Handle race conditions with interrupts
|
thread_done_queue.pop
|
||||||
Thread.current.report_on_exception = false
|
|
||||||
rescue ProcessTerminatedInterrupt
|
rescue ProcessTerminatedInterrupt
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
Thread.pass
|
|
||||||
|
|
||||||
end_time = Time.now + @timeout if @timeout
|
end_time = Time.now + @timeout if @timeout
|
||||||
raise Timeout::Error if raw_wait_thr.join(end_time&.remaining).nil?
|
raise Timeout::Error if raw_wait_thr.join(end_time&.remaining).nil?
|
||||||
|
|
||||||
@status = raw_wait_thr.value
|
@status = raw_wait_thr.value
|
||||||
|
|
||||||
|
thread_ready_queue.pop
|
||||||
line_thread.raise ProcessTerminatedInterrupt.new
|
line_thread.raise ProcessTerminatedInterrupt.new
|
||||||
|
thread_done_queue << true
|
||||||
line_thread.join
|
line_thread.join
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
Process.kill("INT", pid) if pid && !sudo?
|
Process.kill("INT", pid) if pid && !sudo?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user