Exception not caught "Socket exception: Connection reset by peer (104)"
See original GitHub issueSo been wresting with this one for a while. Just saw the note in the repo about opening a ticket for exceptions not caught, so figured this would be the best place to start. My application is fairly large, but the issue is identifiable.
In the app I’m writing, it’s for doing network device upgrades. Regardless of the device, sometimes you’ll get a prompt before it reboots, sometimes you wont. In the cases where you don’t get one and the napalm waits out the netmiko delay_factor, we get the following:
Error trying to Napalm disconnect: ‘Search pattern never detected in send_command_expect: hostname#’
The full function is this:
def device_disconnect_napalm(ssh_napalm=None, log=None):
try:
if ssh_napalm:
if napalm_is_connected(ssh_napalm=ssh_napalm):
time.sleep(2)
ssh_napalm.close()
ssh_napalm = False
log.info('Successfully disconnected the Napalm connection.')
except Exception as e:
log.warning("Error trying to Napalm disconnect: " + repr(str(e)) + " This is normally OK on a disconnect during reboot, so just an FYI.")
log.warning("If a socket exception occurs, also safe to ignore. For some reason I can't catch it.")
ssh_napalm = False
pass
return (ssh_napalm)
You can see my frustration in the log exception (lol)
So, the socket error is (probably) coming from paramiko transport. That kind of makes sense, seeing that none of the 3 modules below the hood (napalm > netmiko > paramiko) know that the device kicked us yet. It’s normally just this: Socket exception: Connection reset by peer (104)
I can’t catch it though. It’s really odd, it just prints it to the screen (which is annoying when the logger is going, for obvious reasons). Is this something we just need to add to the base exceptions file? That’s literally the only log I get 😦
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Related StackOverflow Question
Somewhat anecdotal observation: paramiko 2.4.2 with Python 2.7.x, and didn’t observe this issue.
Seeing the same. I’m observing two different failure modes, both during _check_banner: EOFError and ConnectionResetError.
paramiko 2.4.2 on Python 3.7: