Skip to content

Commit

Permalink
Close the Python sockets when the Websocket closes
Browse files Browse the repository at this point in the history
This allows the client to detect when the connection has been interrupted
  • Loading branch information
anvilpete committed Jan 6, 2025
1 parent e104702 commit 3b58df2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions kubernetes/base/stream/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from six.moves.urllib.parse import urlencode, urlparse, urlunparse
from six import StringIO, BytesIO

from websocket import WebSocket, ABNF, enableTrace
from websocket import WebSocket, ABNF, enableTrace, WebSocketConnectionClosedException
from base64 import urlsafe_b64decode
from requests.utils import should_bypass_proxies

Expand Down Expand Up @@ -379,7 +379,12 @@ def _proxy(self):
if sock == self.websocket:
pending = True
while pending:
opcode, frame = self.websocket.recv_data_frame(True)
try:
opcode, frame = self.websocket.recv_data_frame(True)
except WebSocketConnectionClosedException:
for port in self.local_ports.values():
port.python.close()
return
if opcode == ABNF.OPCODE_BINARY:
if not frame.data:
raise RuntimeError("Unexpected frame data size")
Expand Down

0 comments on commit 3b58df2

Please sign in to comment.