Skip to content

Commit

Permalink
latest docker-py bugfix (npipe) (#513)
Browse files Browse the repository at this point in the history
* socket: handle npipe close on Windows (docker/docker-py#3056)

Fixes docker/docker-py#3045

Cherry-picked from docker/docker-py@3002298

Co-authored-by: Nick Santos <nick.santos@docker.com>

* Add changelog fragment.

Co-authored-by: Nick Santos <nick.santos@docker.com>
  • Loading branch information
felixfontein and nicks authored Dec 1, 2022
1 parent a239c0b commit 2957138
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/513-api-npipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "vendored latest Docker SDK for Python bugfix (https://github.com/ansible-collections/community.docker/pull/513, https://github.com/docker/docker-py/issues/3045)."
14 changes: 14 additions & 0 deletions plugins/module_utils/_api/utils/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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
Expand All @@ -48,6 +53,15 @@ def read(socket, n=4096):
except EnvironmentError 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):
Expand Down

0 comments on commit 2957138

Please sign in to comment.