diff options
author | Michael Merickel <michael@merickel.org> | 2016-10-11 02:38:20 -0500 |
---|---|---|
committer | Michael Merickel <michael@merickel.org> | 2016-11-28 13:31:12 -0600 |
commit | dbd704e68daa16fb91fa2228a9cc2a58219eeec3 (patch) | |
tree | 041720e4291ae45bc62dfab183b4b403f1651506 /docker | |
parent | f36c28926cf9d0e3bfe0f2275c084d63cd3c6169 (diff) | |
download | docker-py-dbd704e68daa16fb91fa2228a9cc2a58219eeec3.tar.gz |
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 <michael@merickel.org>
Diffstat (limited to 'docker')
-rw-r--r-- | docker/utils/socket.py | 10 |
1 files 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 |