Sporadic SSHException: No existing session

Hi everyone,

sometimes i get a SSHException: No existing session during Suite Setup where i connect to my host using key.
The problem is not about the key as this problem occurs “sometimes”.
See the screenshot.

sshlibrary_ssh_exception

I tried to put some variables to check why the error occurs e.g. during the Open Connection i see that a session is there as i get a “1”. see ${ssh_session} = 1
I even added a Sleep of 1 sec between Open Connection and Login with Public Key as i thouht that somehow the “session” need some time to be created?

Well what i know for sure is that if i re-run my test it will work without any changes to e.g. the key.
So the error is sporadic - i don’t get it everytime.

Any Ideas?
Can i add some more variables to check why he claimed that there is no existing session?

Br,
Camil

Here a screenshot with DEBUG output.
The error raise in paramiko/transport.py

Hi Everyone ,

i still get this “No existing Session” Error - but i don’t know why? as it looks like sporadic? but it’s not?!?.
I even add a debug log for the ssh session and i see that ssh_session is = 1 - so there is a session.

see here my logs:

SETUP Open Connection And Log In with key
Start / End / Elapsed:	20240219 18:56:32.203 / 20240219 18:56:36.231 / 00:00:04.028
00:00:00.001KEYWORD BuiltIn . Set Log Level DEBUG
Documentation:	
Sets the log threshold to the specified level and returns the old level.

Start / End / Elapsed:	20240219 18:56:32.203 / 20240219 18:56:32.204 / 00:00:00.001
18:56:32.204	INFO	Log level changed from INFO to DEBUG.	
00:00:00.000KEYWORD ${ssh_session} = SSHLibrary . Open Connection ${HOST}    
Documentation:	
Opens a new SSH connection to the given host and port.

Start / End / Elapsed:	20240219 18:56:32.204 / 20240219 18:56:32.204 / 00:00:00.000
18:56:32.204	**INFO	${ssh_session} = 1**	
00:00:01.001KEYWORD BuiltIn . Sleep 1s
Documentation:	
Pauses the test executed for the given time.

Start / End / Elapsed:	20240219 18:56:32.204 / 20240219 18:56:33.205 / 00:00:01.001
18:56:33.204	INFO	Slept 1 second	
00:00:03.026KEYWORD ${login_with_key_output} = SSHLibrary . Login With Public Key root, 
${SSHKEY}
Documentation:	
Logs into the SSH server using key-based authentication.

Start / End / Elapsed:	20240219 18:56:33.205 / 20240219 18:56:36.231 / 00:00:03.026
18:56:33.206	INFO	Logging into 'x.x.x.x:22' as 'root'.	
18:56:36.219	**FAIL	SSHException: No existing session**	
18:56:36.231	DEBUG	Traceback (most recent call last):
 File "/home/hudson/.local/lib/python3.10/site-packages/SSHLibrary/library.py", line 1077, in 
 login_with_public_key
 return self._login(self.current.login_with_public_key, username,
 File "/home/hudson/.local/lib/python3.10/site-packages/SSHLibrary/library.py", line 1087, in _login
 login_output = login_method(username, *args)
 File "/home/hudson/.local/lib/python3.10/site-packages/SSHLibrary/abstractclient.py", line 284, in 
login_with_public_key
  self._login_with_public_key(username, keyfile, password,
 File "/home/hudson/.local/lib/python3.10/site-packages/SSHLibrary/pythonclient.py", line 229, in 
_login_with_public_key
  self.client.connect(self.config.host, self.config.port, username,
 File "/home/hudson/.local/lib/python3.10/site-packages/paramiko/client.py", line 457, in connect
   server_key = t.get_remote_server_key()
 File "/home/hudson/.local/lib/python3.10/site-packages/paramiko/transport.py", line 902, in 
get_remote_server_key
raise SSHException("No existing session")
paramiko.ssh_exception.SSHException: No existing session

So as you can see after
${ssh_session} = SSHLibrary . Open Connection ${HOST}
i put a 1 sec sleep - just for testing.
And the ${ssh_session} is showing a “1” - so its fine

Thus why do i get " paramiko.ssh_exception.SSHException: No existing session" ??

Anyone some idea?

Hi Camil,

You mentioned it’s a sporadic/random behavior, but if you run again login works each type the problem occurs (means no problems for a while) ?

As Paramiko doesn’t find any active session, and throw exception, it might have been closed or lost/not accessible anymore between open and login.

For close :

  • Did you try to increase the sleep to check behavior?
  • Or maybe add the timeout argument to ‘Open connection’
  • the shared log seems simple, meaning no other closing action seems to interfere

Not accessible :

  • Can you envision a network random issue, fitting with the problem?
  • Is there logs on the target server?
  • Maybe try connection directly with Paramiko, i.e. through a .py script, to isolate issue

Seems always basic, but check library version updates, dependencies too…

Regards

“Issue” can also be on the sshd on the host you are connecting to;

First you have open connection
then you sleep for 1 second
Then you try to authenticate.

Now, if the LoginGraceTime is enabled and set to some low value (1 second in this case) – this is what happens… I’d drop the Sleep completely, it should not be necessary.

On similar matter, if you are running these tests in parallel (like with pabot) or there’s connections from same network/host to the sshd … Depending on the values in the sshd with MaxSessions, MaxStartups and PerSourceMaxStartups, sshd in the remote end can drop your connection request and paramiko throws that exception you are seeing.

1 Like

Hi,

thank you for your replies. I will try out to find this sporadic issue.
I haven’t checked the logs on my server where RF tries to connect to. I will do this once this error appear again.

Yea i will remove the 1sec. sleep - it’s not necessary. I was just thinking that after Open Connection and Authenticate the session might not be there - that’s why i just wanted to wait 1 sec before trying to authenticate.

This test does not have any other parallel connections. It runs as single test.

br,
camil

Hi Camil,

better to use a Read Until type keyword instead of a Sleep, that way if there is a few ms delay your script will wait till the session is ready but not wait too long.

Dave.