Skip to content

Commit 7625d08

Browse files
committed
Stop TLS sockets being closed when attaching
When calling attach_socket, the response is garbage collected, which triggers a close method on the file object, closing the socket. This stop the response from being garbage collected until we've finished with the underlying socket. Fixes #350 Signed-off-by: Ben Firshman <[email protected]>
1 parent a22ee2a commit 7625d08

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docker/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,11 @@ def _create_websocket_connection(self, url):
259259
def _get_raw_response_socket(self, response):
260260
self._raise_for_status(response)
261261
if six.PY3:
262-
return response.raw._fp.fp.raw._sock
262+
sock = response.raw._fp.fp.raw._sock
263263
else:
264-
return response.raw._fp.fp._sock
264+
sock = response.raw._fp.fp._sock
265+
sock._response = response
266+
return sock
265267

266268
def _stream_helper(self, response):
267269
"""Generator for data coming from a chunked-encoded HTTP response."""

0 commit comments

Comments
 (0)