@@ -249,6 +249,10 @@ def __init__(self, websocket, ports):
249
249
daemon = True
250
250
).start ()
251
251
252
+ @property
253
+ def connected (self ):
254
+ return self .websocket .connected
255
+
252
256
def socket (self , port_number ):
253
257
if port_number not in self .local_ports :
254
258
raise ValueError ("Invalid port number" )
@@ -276,8 +280,8 @@ def __init__(self, ix, port_number):
276
280
s , self .python = socket .socketpair (socket .AF_UNIX , socket .SOCK_STREAM )
277
281
# The self.socket half of the pair is used by the python application to send
278
282
# and receive data to the eventual pod port. It is wrapped in the _Socket class
279
- # because a socket pair is an AF_UNIX socket, not a AF_NET socket. This allows
280
- # intercepting setting AF_INET socket options that would error against an AD_UNIX
283
+ # because a socket pair is an AF_UNIX socket, not a AF_INET socket. This allows
284
+ # intercepting setting AF_INET socket options that would error against an AF_UNIX
281
285
# socket.
282
286
self .socket = self ._Socket (s )
283
287
# Data accumulated from the websocket to be sent to the python application.
@@ -325,17 +329,17 @@ def _proxy(self):
325
329
local_all_closed = True
326
330
for port in self .local_ports .values ():
327
331
if port .python .fileno () != - 1 :
328
- if self .websocket .connected :
329
- rlist .append (port .python )
330
- if port .data :
331
- wlist .append (port .python )
332
- local_all_closed = False
333
- else :
332
+ if port .error or not self .websocket .connected :
334
333
if port .data :
335
334
wlist .append (port .python )
336
335
local_all_closed = False
337
336
else :
338
337
port .python .close ()
338
+ else :
339
+ rlist .append (port .python )
340
+ if port .data :
341
+ wlist .append (port .python )
342
+ local_all_closed = False
339
343
if local_all_closed and not (self .websocket .connected and kubernetes_data ):
340
344
self .websocket .close ()
341
345
return
0 commit comments