We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5261fb6 + 1e89f5c commit 77b0d1dCopy full SHA for 77b0d1d
1 file changed
netmiko/base_connection.py
@@ -487,7 +487,21 @@ def __init__(
487
488
# Establish the remote connection
489
if auto_connect:
490
- self._open()
+ try:
491
+ self._open()
492
+ except Exception:
493
+ # If the connection fails before disconnect() is ever reached
494
+ # (establish_connection errors: authentication, TCP timeout,
495
+ # SSH key-exchange/negotiation), the SecretsFilter registered
496
+ # above would be stranded on the module logger and leaked.
497
+ # Remove it (and close any session log) before propagating.
498
499
+ log.removeFilter(self._secrets_filter)
500
+ if self.session_log:
501
+ self.session_log.close()
502
503
+ pass
504
+ raise
505
506
def _open(self) -> None:
507
"""Decouple connection creation from __init__ for mocking."""
0 commit comments