Skip to content

Commit 6376733

Browse files
committed
External process output should be read asynchronously to avoid deadlocks
1 parent 4b33941 commit 6376733

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

rake-tasks/buck.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,25 @@ def self.buck_cmd(command, args, &block)
6060
args ||= []
6161
buck.push(command)
6262
buck.push(*args)
63+
puts buck.join(' ')
6364

6465
output = ''
6566
Open3.popen3(*buck) do |stdin, stdout, stderr, wait|
66-
stdin.close
67-
68-
while (error = stderr.gets)
69-
STDERR.print(error)
67+
Thread.new do
68+
while (error = stderr.gets)
69+
STDERR.print(error)
70+
end
7071
end
7172

72-
while (line = stdout.gets)
73-
output << line
74-
STDOUT.print line
73+
Thread.new do
74+
while (line = stdout.gets)
75+
output << line
76+
STDOUT.print line
77+
end
7578
end
7679

80+
stdin.close
81+
7782
raise "#{buck.join(' ')} failed with exit code: #{wait.value.exitstatus}" unless wait.value.success?
7883
end
7984

0 commit comments

Comments
 (0)