mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-06-19 04:37:47 +00:00
Close response instead of derived socket. (#1260)
This commit is contained in:
parent
3bec6b2add
commit
5afe15ea50
4
changelogs/fragments/1260-close.yml
Normal file
4
changelogs/fragments/1260-close.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "docker_container_exec module, docker_api connection plugin - ensure that when a command is run in a container with stdin provided, that the actual response is closed and not a socket derived from it.
|
||||||
|
The old behavior causes warnings to be shown on Python 3.13+ under certain conditions
|
||||||
|
(https://github.com/ansible-collections/community.docker/issues/1247, https://github.com/ansible-collections/community.docker/pull/1260)."
|
||||||
@ -303,7 +303,7 @@ class Connection(ConnectionBase):
|
|||||||
|
|
||||||
data = {"Tty": False, "Detach": False}
|
data = {"Tty": False, "Detach": False}
|
||||||
if need_stdin:
|
if need_stdin:
|
||||||
exec_socket = self._call_client(
|
exec_socket, response = self._call_client(
|
||||||
lambda client: client.post_json_to_stream_socket(
|
lambda client: client.post_json_to_stream_socket(
|
||||||
"/exec/{0}/start", exec_id, data=data
|
"/exec/{0}/start", exec_id, data=data
|
||||||
)
|
)
|
||||||
@ -356,7 +356,7 @@ class Connection(ConnectionBase):
|
|||||||
|
|
||||||
stdout, stderr = exec_socket_handler.consume()
|
stdout, stderr = exec_socket_handler.consume()
|
||||||
finally:
|
finally:
|
||||||
exec_socket.close()
|
response.close()
|
||||||
else:
|
else:
|
||||||
stdout, stderr = self._call_client(
|
stdout, stderr = self._call_client(
|
||||||
lambda client: client.post_json_to_stream(
|
lambda client: client.post_json_to_stream(
|
||||||
|
|||||||
@ -795,7 +795,7 @@ class APIClient(_Session):
|
|||||||
data: t.Any = None,
|
data: t.Any = None,
|
||||||
headers: dict[str, str] | None = None,
|
headers: dict[str, str] | None = None,
|
||||||
**kwargs: t.Any,
|
**kwargs: t.Any,
|
||||||
) -> SocketLike:
|
) -> tuple[SocketLike, Response]:
|
||||||
headers = headers.copy() if headers else {}
|
headers = headers.copy() if headers else {}
|
||||||
headers.update(
|
headers.update(
|
||||||
{
|
{
|
||||||
@ -803,15 +803,14 @@ class APIClient(_Session):
|
|||||||
"Upgrade": "tcp",
|
"Upgrade": "tcp",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return self._get_raw_response_socket(
|
response = self._post_json(
|
||||||
self._post_json(
|
self._url(pathfmt, *args, versioned_api=True),
|
||||||
self._url(pathfmt, *args, versioned_api=True),
|
data,
|
||||||
data,
|
headers=headers,
|
||||||
headers=headers,
|
stream=True,
|
||||||
stream=True,
|
**kwargs,
|
||||||
**kwargs,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
return self._get_raw_response_socket(response), response
|
||||||
|
|
||||||
@t.overload
|
@t.overload
|
||||||
def post_json_to_stream(
|
def post_json_to_stream(
|
||||||
|
|||||||
@ -274,7 +274,7 @@ def main() -> None:
|
|||||||
stdout: bytes | None
|
stdout: bytes | None
|
||||||
stderr: bytes | None
|
stderr: bytes | None
|
||||||
if stdin and not detach:
|
if stdin and not detach:
|
||||||
exec_socket = client.post_json_to_stream_socket(
|
exec_socket, response = client.post_json_to_stream_socket(
|
||||||
"/exec/{0}/start", exec_id, data=data
|
"/exec/{0}/start", exec_id, data=data
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
@ -286,7 +286,7 @@ def main() -> None:
|
|||||||
|
|
||||||
stdout, stderr = exec_socket_handler.consume()
|
stdout, stderr = exec_socket_handler.consume()
|
||||||
finally:
|
finally:
|
||||||
exec_socket.close()
|
response.close()
|
||||||
elif tty:
|
elif tty:
|
||||||
stdout, stderr = client.post_json_to_stream(
|
stdout, stderr = client.post_json_to_stream(
|
||||||
"/exec/{0}/start",
|
"/exec/{0}/start",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user