From dbd704e68daa16fb91fa2228a9cc2a58219eeec3 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Tue, 11 Oct 2016 02:38:20 -0500 Subject: do not assume that read will consume the number of bytes requested The issue is that ``os.read`` does not always read the expected number of bytes, and thus we are moving to the next frame too early causing drift in the byte stream. When the reading drifts, it starts reading garbage as the next frame size. The some examples of frame sizes were 4032897957 bytes, etc. Values this large were causing the exceptions from ``os.read``. fixes #1211 Signed-off-by: Michael Merickel --- docker/utils/socket.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docker/utils/socket.py b/docker/utils/socket.py index 164b845..4080f25 100644 --- a/docker/utils/socket.py +++ b/docker/utils/socket.py @@ -69,7 +69,11 @@ def frames_iter(socket): """ Returns a generator of frames read from socket """ - n = next_frame_size(socket) - while n > 0: - yield read(socket, n) + while True: n = next_frame_size(socket) + if n == 0: + break + while n > 0: + result = read(socket, n) + n -= len(result) + yield result -- cgit v1.2.1