@@ -274,7 +274,7 @@ def self.instance_key(cmd, args, options)
274274 def self . is_readable? ( stream , timeout = 0.5 )
275275 raise Errno ::EPIPE if !is_stream_valid? ( stream )
276276 read_ready = IO . select ( [ stream ] , [ ] , [ ] , timeout )
277- read_ready && stream == read_ready [ 0 ] [ 0 ]
277+ read_ready && stream == read_ready [ 0 ] [ 0 ] && ! stream . eof?
278278 end
279279
280280 # when a stream has been closed by handle, but Ruby still has a file
@@ -395,17 +395,16 @@ def read_streams
395395 # read a Little Endian 32-bit integer for length of response
396396 expected_response_length = pipe . sysread ( 4 ) . unpack ( 'V' ) . first
397397
398- if expected_response_length == 0
399- nil
400- else
401- # reads the expected bytes as a binary string or fails
402- buffer = ""
403- # Reads in the pipe data 8K, or less, at a time
404- while ( buffer . length < expected_response_length )
405- buffer << pipe . sysread ( [ expected_response_length - buffer . length , 8192 ] . min )
406- end
407- buffer
398+ next nil if expected_response_length == 0
399+ # reads the expected bytes as a binary string or fails
400+ buffer = ""
401+ # sysread may not return all of the requested bytes due to buffering or the
402+ # underlying IO system. Keep reading from the pipe until all the bytes are read
403+ loop do
404+ buffer . concat ( pipe . sysread ( expected_response_length - buffer . length ) )
405+ break if buffer . length >= expected_response_length
408406 end
407+ buffer
409408 end
410409
411410 Puppet . debug "Waited #{ Time . now - start_time } total seconds."
0 commit comments