Skip to content

Commit

Permalink
socket: handle npipe close. Fixes docker#3045
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks committed Oct 21, 2022
1 parent bc0a5fb commit ed9b73e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docker/utils/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
except ImportError:
NpipeSocket = type(None)

import pywintypes


STDOUT = 1
STDERR = 2
Expand All @@ -17,6 +19,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):
"""
Expand All @@ -34,10 +39,18 @@ def read(socket, n=4096):
if isinstance(socket, getattr(pysocket, 'SocketIO')):
return socket.read(n)
return os.read(socket.fileno(), n)

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.
return 0
raise


def read_exactly(socket, n):
"""
Expand Down

0 comments on commit ed9b73e

Please sign in to comment.