@@ -249,6 +249,10 @@ def __init__(self, websocket, ports):
249249 daemon = True
250250 ).start ()
251251
252+ @property
253+ def connected (self ):
254+ return self .websocket .connected
255+
252256 def socket (self , port_number ):
253257 if port_number not in self .local_ports :
254258 raise ValueError ("Invalid port number" )
@@ -276,8 +280,8 @@ def __init__(self, ix, port_number):
276280 s , self .python = socket .socketpair (socket .AF_UNIX , socket .SOCK_STREAM )
277281 # The self.socket half of the pair is used by the python application to send
278282 # 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
281285 # socket.
282286 self .socket = self ._Socket (s )
283287 # Data accumulated from the websocket to be sent to the python application.
@@ -325,17 +329,17 @@ def _proxy(self):
325329 local_all_closed = True
326330 for port in self .local_ports .values ():
327331 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 :
334333 if port .data :
335334 wlist .append (port .python )
336335 local_all_closed = False
337336 else :
338337 port .python .close ()
338+ else :
339+ rlist .append (port .python )
340+ if port .data :
341+ wlist .append (port .python )
342+ local_all_closed = False
339343 if local_all_closed and not (self .websocket .connected and kubernetes_data ):
340344 self .websocket .close ()
341345 return
0 commit comments