@@ -243,11 +243,12 @@ def __init__(self, websocket, ports):
243
243
# There is a thread run per PortForward instance which performs the translation between the
244
244
# raw socket data sent by the python application and the websocket protocol. This thread
245
245
# terminates after either side has closed all ports, and after flushing all pending data.
246
- threading .Thread (
246
+ proxy = threading .Thread (
247
247
name = "Kubernetes port forward proxy: %s" % ', ' .join ([str (port ) for port in ports ]),
248
- target = self ._proxy ,
249
- daemon = True
250
- ).start ()
248
+ target = self ._proxy
249
+ )
250
+ proxy .daemon = True
251
+ proxy .start ()
251
252
252
253
@property
253
254
def connected (self ):
@@ -272,7 +273,7 @@ def __init__(self, ix, port_number):
272
273
# The remote port number
273
274
self .port_number = port_number
274
275
# The websocket channel byte number for this port
275
- self .channel = bytes ([ ix * 2 ] )
276
+ self .channel = six . int2byte ( ix * 2 )
276
277
# A socket pair is created to provide a means of translating the data flow
277
278
# between the python application and the kubernetes websocket. The self.python
278
279
# half of the socket pair is used by the _proxy method to receive and send data
@@ -350,9 +351,9 @@ def _proxy(self):
350
351
if opcode == ABNF .OPCODE_BINARY :
351
352
if not frame .data :
352
353
raise RuntimeError ("Unexpected frame data size" )
353
- channel = frame .data [ 0 ]
354
+ channel = six . byte2int ( frame .data )
354
355
if channel >= len (channel_ports ):
355
- raise RuntimeError ("Unexpected channel number: " + str ( channel ) )
356
+ raise RuntimeError ("Unexpected channel number: %s" % channel )
356
357
port = channel_ports [channel ]
357
358
if channel_initialized [channel ]:
358
359
if channel % 2 :
@@ -366,14 +367,14 @@ def _proxy(self):
366
367
raise RuntimeError (
367
368
"Unexpected initial channel frame data size"
368
369
)
369
- port_number = frame .data [1 ] + (frame .data [2 ] * 256 )
370
+ port_number = six . byte2int ( frame .data [1 : 2 ]) + (six . byte2int ( frame .data [2 : 3 ]) * 256 )
370
371
if port_number != port .port_number :
371
372
raise RuntimeError (
372
- "Unexpected port number in initial channel frame: " + str ( port_number )
373
+ "Unexpected port number in initial channel frame: %s" % port_number
373
374
)
374
375
channel_initialized [channel ] = True
375
376
elif opcode not in (ABNF .OPCODE_PING , ABNF .OPCODE_PONG , ABNF .OPCODE_CLOSE ):
376
- raise RuntimeError ("Unexpected websocket opcode: " + str ( opcode ) )
377
+ raise RuntimeError ("Unexpected websocket opcode: %s" % opcode )
377
378
else :
378
379
port = local_ports [sock ]
379
380
data = port .python .recv (1024 * 1024 )
0 commit comments