@@ -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
0 commit comments