Skip to content

Close the Python sockets when the Websocket closes #2316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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