Skip to content

Read stream from BufferedReader #3333

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docker/api/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import json
import struct
import urllib
Expand Down Expand Up @@ -428,6 +429,9 @@ def _read_from_socket(self, response, stream, tty=True, demux=False):
"""
socket = self._get_raw_response_socket(response)

if isinstance(response.raw._fp.fp, io.BufferedReader):
socket = response.raw._fp.fp

gen = frames_iter(socket, tty)

if demux:
Expand Down
5 changes: 3 additions & 2 deletions docker/utils/socket.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import errno
import io
import os
import select
import socket as pysocket
Expand Down Expand Up @@ -30,7 +31,7 @@ def read(socket, n=4096):

recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK)

if not isinstance(socket, NpipeSocket):
if not isinstance(socket, NpipeSocket) and not isinstance(socket, io.BufferedReader):
if not hasattr(select, "poll"):
# Limited to 1024
select.select([socket], [], [])
Expand All @@ -42,7 +43,7 @@ def read(socket, n=4096):
try:
if hasattr(socket, 'recv'):
return socket.recv(n)
if isinstance(socket, pysocket.SocketIO):
if isinstance(socket, pysocket.SocketIO) or isinstance(socket, io.BufferedReader):
return socket.read(n)
return os.read(socket.fileno(), n)
except OSError as e:
Expand Down