summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Santos <nick.santos@docker.com>2022-11-02 15:31:00 -0400
committerGitHub <noreply@github.com>2022-11-02 15:31:00 -0400
commit30022984f6445fbc322cbe97bb99aab1ddb1e4fd (patch)
tree9f07a69c55c94ead35a690f2c00881185313ed26
parentbc0a5fbacd7617fd338d121adca61600fc70d221 (diff)
downloaddocker-py-30022984f6445fbc322cbe97bb99aab1ddb1e4fd.tar.gz
socket: handle npipe close on Windows (#3056)6.0.1
Fixes https://github.com/docker/docker-py/issues/3045 Signed-off-by: Nick Santos <nick.santos@docker.com>
-rw-r--r--docker/utils/socket.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/docker/utils/socket.py b/docker/utils/socket.py
index 4a2076e..5aca30b 100644
--- a/docker/utils/socket.py
+++ b/docker/utils/socket.py
@@ -18,6 +18,11 @@ class SocketError(Exception):
pass
+# NpipeSockets have their own error types
+# pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')
+NPIPE_ENDED = 109
+
+
def read(socket, n=4096):
"""
Reads at most n bytes from socket
@@ -37,6 +42,15 @@ def read(socket, n=4096):
except OSError as e:
if e.errno not in recoverable_errors:
raise
+ except Exception as e:
+ is_pipe_ended = (isinstance(socket, NpipeSocket) and
+ len(e.args) > 0 and
+ e.args[0] == NPIPE_ENDED)
+ if is_pipe_ended:
+ # npipes don't support duplex sockets, so we interpret
+ # a PIPE_ENDED error as a close operation (0-length read).
+ return 0
+ raise
def read_exactly(socket, n):