Skip to content

Commit fb69078

Browse files
committed
Halfway to a fix..
1 parent a5ef340 commit fb69078

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

chef/lib/chef/mixin/command.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ def run_command(args={})
112112
exec_processing_block = lambda do |pid, stdin, stdout, stderr|
113113
stdin.close
114114

115-
Timeout.timeout(Chef::Config[:run_command_stdout_timeout]) do
115+
begin
116+
Timeout.timeout(Chef::Config[:run_command_stdout_timeout]) do
117+
while stdout.ready? == nil
118+
Chef::Log.debug("Waiting for STDOUT to be ready..")
119+
sleep 1
120+
end
121+
end
122+
rescue Timeout::Error => e
123+
Chef::Log.error("#{args[:command]} timed out reading STDOUT")
124+
else
116125
stdout_string = stdout.gets(nil)
117126
if stdout_string
118127
command_stdout = stdout_string
@@ -121,7 +130,17 @@ def run_command(args={})
121130
Chef::Log.debug("---- End #{args[:command]} STDOUT ----")
122131
end
123132
end
124-
Timeout.timeout(Chef::Config[:run_command_stderr_timeout]) do
133+
134+
begin
135+
Timeout.timeout(Chef::Config[:run_command_stderr_timeout]) do
136+
while stderr.ready? == nil
137+
Chef::Log.debug("Waiting for STDERR to be ready..")
138+
sleep 1
139+
end
140+
end
141+
rescue Timeout::Error => e
142+
Chef::Log.error("#{args[:command]} timed out reading STDERR")
143+
else
125144
stderr_string = stderr.gets(nil)
126145
if stderr_string
127146
command_stderr = stderr_string
@@ -130,6 +149,7 @@ def run_command(args={})
130149
Chef::Log.debug("---- End #{args[:command]} STDERR ----")
131150
end
132151
end
152+
133153
end
134154

135155
args[:cwd] ||= Dir.tmpdir
@@ -144,7 +164,7 @@ def run_command(args={})
144164
Timeout.timeout(args[:timeout]) do
145165
status = popen4(args[:command], args, &exec_processing_block)
146166
end
147-
rescue Exception => e
167+
rescue Timeout::Error => e
148168
Chef::Log.error("#{args[:command_string]} exceeded timeout #{args[:timeout]}")
149169
raise(e)
150170
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Cookbook Name:: CHEF-44
3+
# Recipe:: default
4+
#
5+
# Copyright 2009, Opscode
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
21+
execute "sleepy" do
22+
Chef::Config[:run_command_stdout_timeout] = 1
23+
Chef::Config[:run_command_stderr_timeout] = 1
24+
command "sleep 5"
25+
end
26+
27+
28+
execute "sleepy2" do
29+
Chef::Config[:run_command_stdout_timeout] = 120
30+
Chef::Config[:run_command_stderr_timeout] = 120
31+
command "sleep 5"
32+
end
33+

0 commit comments

Comments
 (0)