Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b58df2

Browse files
committed
Close the Python sockets when the Websocket closes
This allows the client to detect when the connection has been interrupted
1 parent e104702 commit 3b58df2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kubernetes/base/stream/ws_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from six.moves.urllib.parse import urlencode, urlparse, urlunparse
3131
from six import StringIO, BytesIO
3232

33-
from websocket import WebSocket, ABNF, enableTrace
33+
from websocket import WebSocket, ABNF, enableTrace, WebSocketConnectionClosedException
3434
from base64 import urlsafe_b64decode
3535
from requests.utils import should_bypass_proxies
3636

@@ -379,7 +379,12 @@ def _proxy(self):
379379
if sock == self.websocket:
380380
pending = True
381381
while pending:
382-
opcode, frame = self.websocket.recv_data_frame(True)
382+
try:
383+
opcode, frame = self.websocket.recv_data_frame(True)
384+
except WebSocketConnectionClosedException:
385+
for port in self.local_ports.values():
386+
port.python.close()
387+
return
383388
if opcode == ABNF.OPCODE_BINARY:
384389
if not frame.data:
385390
raise RuntimeError("Unexpected frame data size")

0 commit comments

Comments
 (0)