Skip to content

Commit

Permalink
Large Output Shell Stall
Browse files Browse the repository at this point in the history
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 #507]
  • Loading branch information
nebhale committed Oct 30, 2017
1 parent e816391 commit f0c478c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/java_buildpack/util/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ module Shell
# @return [Void]
def shell(*args)
Open3.popen3(*args) do |_stdin, stdout, stderr, wait_thr|
out = stdout.gets nil
err = stderr.gets nil

unless wait_thr.value.success?
puts "\nCommand '#{args.join ' '}' has failed"
puts "STDOUT: #{stdout.gets nil}"
puts "STDERR: #{stderr.gets nil}"
puts "STDOUT: #{out}"
puts "STDERR: #{err}"

raise
end
Expand Down
5 changes: 5 additions & 0 deletions spec/java_buildpack/util/shell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
require 'spec_helper'
require 'console_helper'
require 'java_buildpack/util/shell'
require 'timeout'

describe JavaBuildpack::Util::Shell do
include described_class
Expand All @@ -29,4 +30,8 @@
expect { shell 'false' }.to raise_error
end

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

end

0 comments on commit f0c478c

Please sign in to comment.