Skip to content

Commit 3002298

Browse files
authored
socket: handle npipe close on Windows (#3056)
Fixes #3045 Signed-off-by: Nick Santos <[email protected]>
1 parent bc0a5fb commit 3002298

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docker/utils/socket.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class SocketError(Exception):
1818
pass
1919

2020

21+
# NpipeSockets have their own error types
22+
# pywintypes.error: (109, 'ReadFile', 'The pipe has been ended.')
23+
NPIPE_ENDED = 109
24+
25+
2126
def read(socket, n=4096):
2227
"""
2328
Reads at most n bytes from socket
@@ -37,6 +42,15 @@ def read(socket, n=4096):
3742
except OSError as e:
3843
if e.errno not in recoverable_errors:
3944
raise
45+
except Exception as e:
46+
is_pipe_ended = (isinstance(socket, NpipeSocket) and
47+
len(e.args) > 0 and
48+
e.args[0] == NPIPE_ENDED)
49+
if is_pipe_ended:
50+
# npipes don't support duplex sockets, so we interpret
51+
# a PIPE_ENDED error as a close operation (0-length read).
52+
return 0
53+
raise
4054

4155

4256
def read_exactly(socket, n):

0 commit comments

Comments
 (0)