From 8cd2eaac00bbfecdcc36e367469aee0fbb635468 Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Fri, 21 Oct 2022 18:44:01 -0400 Subject: [PATCH] socket: handle npipe close. Fixes https://github.com/docker/docker-py/issues/3045 Signed-off-by: Nick Santos --- docker/utils/socket.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docker/utils/socket.py b/docker/utils/socket.py index 4a2076ec4a..9be6ae11a0 100644 --- a/docker/utils/socket.py +++ b/docker/utils/socket.py @@ -17,6 +17,9 @@ 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): """ @@ -37,6 +40,12 @@ def read(socket, n=4096): except OSError as e: if e.errno not in recoverable_errors: raise + except Exception as e: + if isinstance(socket, NpipeSocket) and len(e.args) > 0 and e.args[0] == NPIPE_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):