@@ -399,6 +399,8 @@ def __init__(self, kernel_manager, proxy_config):
399
399
self .ip = None
400
400
self .pid = 0
401
401
self .pgid = 0
402
+ self .remote_user = None
403
+ self .remote_pwd = None
402
404
403
405
@abc .abstractmethod
404
406
async def launch_process (self , kernel_cmd , ** kwargs ):
@@ -584,14 +586,14 @@ def _get_ssh_client(self, host):
584
586
"""
585
587
ssh = None
586
588
587
- global remote_user
588
- global remote_pwd
589
589
use_gss = os .getenv ("EG_REMOTE_GSS_SSH" , None )
590
590
if remote_user is None :
591
- remote_pwd = os .getenv ("EG_REMOTE_PWD" ) # this should use password-less ssh
592
- remote_user = os .getenv ("EG_REMOTE_USER" , getpass .getuser ())
591
+ self .remote_pwd = os .getenv (
592
+ "EG_REMOTE_PWD"
593
+ ) # this should use password-less ssh
594
+ self .remote_user = os .getenv ("EG_REMOTE_USER" , getpass .getuser ())
593
595
594
- if use_gss and (remote_pwd or remote_user ):
596
+ if use_gss and (self . remote_pwd or self . remote_user ):
595
597
warnings .warn (
596
598
"Both `EG_REMOTE_GSS_SSH` and one of `EG_REMOTE_PWD` or `EG_REMOTE_USER` is set. "
597
599
"Those options are mutually exclusive, you configuration may be incorrect. "
@@ -603,18 +605,23 @@ def _get_ssh_client(self, host):
603
605
ssh .load_system_host_keys ()
604
606
host_ip = gethostbyname (host )
605
607
if use_gss :
608
+ self .log .debug ("Connecting to remote host via GSS." )
606
609
ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
607
610
ssh .connect (host_ip , port = ssh_port , gss_auth = True )
608
611
else :
609
612
ssh .set_missing_host_key_policy (paramiko .RejectPolicy ())
610
- if remote_pwd :
613
+ if self .remote_pwd :
614
+ self .log .debug (
615
+ "Connecting to remote host with username and password."
616
+ )
611
617
ssh .connect (
612
618
host_ip ,
613
619
port = ssh_port ,
614
- username = remote_user ,
615
- password = remote_pwd ,
620
+ username = self . remote_user ,
621
+ password = self . remote_pwd ,
616
622
)
617
623
else :
624
+ self .log .debug ("Connecting to remote host with ssh key." )
618
625
ssh .connect (host_ip , port = ssh_port , username = remote_user )
619
626
except Exception as e :
620
627
http_status_code = 500
@@ -1284,12 +1291,23 @@ def _send_listener_request(self, request, shutdown_socket=False):
1284
1291
sock .shutdown (SHUT_WR )
1285
1292
except Exception as e2 :
1286
1293
if isinstance (e2 , OSError ) and e2 .errno == errno .ENOTCONN :
1287
- pass # Listener is not connected. This is probably a follow-on to ECONNREFUSED on connect
1294
+ # Listener is not connected. This is probably a follow-on to ECONNREFUSED on connect
1295
+ self .log .debug (
1296
+ "ERROR: OSError(ENOTCONN) raised on socket shutdown, "
1297
+ "listener likely not connected. Cannot send {request}" ,
1298
+ request = request ,
1299
+ )
1288
1300
else :
1289
1301
self .log .warning ("Exception occurred attempting to shutdown communication socket to {}:{} "
1290
1302
"for KernelID '{}' (ignored): {}" .format (self .comm_ip , self .comm_port ,
1291
1303
self .kernel_id , str (e2 )))
1292
1304
sock .close ()
1305
+ else :
1306
+ self .log .debug (
1307
+ "Invalid comm port, not sending request '{}' to comm_port '{}'." ,
1308
+ request ,
1309
+ self .comm_port ,
1310
+ )
1293
1311
1294
1312
def send_signal (self , signum ):
1295
1313
"""
@@ -1303,17 +1321,20 @@ def send_signal(self, signum):
1303
1321
# using anything other than the socket-based signal (via signal_addr) will not work.
1304
1322
1305
1323
if self .comm_port > 0 :
1306
- signal_request = dict ()
1307
- signal_request ['signum' ] = signum
1308
1324
1309
1325
try :
1310
- self ._send_listener_request (signal_request )
1326
+ self ._send_listener_request ({ "signum" : signum } )
1311
1327
1312
1328
if signum > 0 : # Polling (signum == 0) is too frequent
1313
1329
self .log .debug ("Signal ({}) sent via gateway communication port." .format (signum ))
1314
1330
return None
1315
1331
except Exception as e :
1316
- if isinstance (e , OSError ) and e .errno == errno .ECONNREFUSED : # Return False since there's no process.
1332
+ if (
1333
+ isinstance (e , OSError ) and e .errno == errno .ECONNREFUSED
1334
+ ): # Return False since there's no process.
1335
+ self .log .debug (
1336
+ "ERROR: ECONNREFUSED, no process listening, cannot send signal."
1337
+ )
1317
1338
return False
1318
1339
1319
1340
self .log .warning ("An unexpected exception occurred sending signal ({}) for KernelID '{}': {}"
0 commit comments