Skip to content

Commit f0c478c

Browse files
committed
Large Output Shell Stall
Previously if a large amount of output was received during a shell call, the buildpack would stall because the process' output buffer would fill to capacity before the process would complete. This change assigns the output to a variable during execution, ensuring that the process' output buffers do not fill during execution. [resolves cloudfoundry#507]
1 parent e816391 commit f0c478c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/java_buildpack/util/shell.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ module Shell
2828
# @return [Void]
2929
def shell(*args)
3030
Open3.popen3(*args) do |_stdin, stdout, stderr, wait_thr|
31+
out = stdout.gets nil
32+
err = stderr.gets nil
33+
3134
unless wait_thr.value.success?
3235
puts "\nCommand '#{args.join ' '}' has failed"
33-
puts "STDOUT: #{stdout.gets nil}"
34-
puts "STDERR: #{stderr.gets nil}"
36+
puts "STDOUT: #{out}"
37+
puts "STDERR: #{err}"
3538

3639
raise
3740
end

spec/java_buildpack/util/shell_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
require 'spec_helper'
1717
require 'console_helper'
1818
require 'java_buildpack/util/shell'
19+
require 'timeout'
1920

2021
describe JavaBuildpack::Util::Shell do
2122
include described_class
@@ -29,4 +30,8 @@
2930
expect { shell 'false' }.to raise_error
3031
end
3132

33+
it 'handles a large amount of output' do
34+
Timeout.timeout(2) { shell "cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 1000000 | head -n 1" }
35+
end
36+
3237
end

0 commit comments

Comments
 (0)