Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
paramiko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
Python
Modules
paramiko
Commits
7c97063c00d0
Commit
7c97063c00d0
authored
3 years ago
by
Jeff Forcier
Browse files
Options
Downloads
Plain Diff
Merge branch '2.9' into 2.10
parents
13014a6b914b
ef1d43504a27
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
paramiko/client.py
+4
-0
4 additions, 0 deletions
paramiko/client.py
sites/www/changelog.rst
+7
-0
7 additions, 0 deletions
sites/www/changelog.rst
tests/test_client.py
+18
-0
18 additions, 0 deletions
tests/test_client.py
with
29 additions
and
0 deletions
paramiko/client.py
+
4
−
0
View file @
7c97063c
...
@@ -350,6 +350,10 @@
...
@@ -350,6 +350,10 @@
# Break out of the loop on success
# Break out of the loop on success
break
break
except
socket
.
error
as
e
:
except
socket
.
error
as
e
:
# As mentioned in socket docs it is better
# to close sockets explicitly
if
sock
:
sock
.
close
()
# Raise anything that isn't a straight up connection error
# Raise anything that isn't a straight up connection error
# (such as a resolution error)
# (such as a resolution error)
if
e
.
errno
not
in
(
ECONNREFUSED
,
EHOSTUNREACH
):
if
e
.
errno
not
in
(
ECONNREFUSED
,
EHOSTUNREACH
):
...
...
This diff is collapsed.
Click to expand it.
sites/www/changelog.rst
+
7
−
0
View file @
7c97063c
...
@@ -2,6 +2,13 @@
...
@@ -2,6 +2,13 @@
Changelog
Changelog
=========
=========
- :bug:`1822` (via, and relating to, far too many other issues to mention here)
Update `~paramiko.client.SSHClient` so it explicitly closes its wrapped
socket object upon encountering socket errors at connection time. This should
help somewhat with certain classes of memory leaks, resource warnings, and/or
errors (though we hasten to remind everyone that Client and Transport have
their own ``.close()`` methods for use in non-error situations!). Patch
courtesy of ``@YoavCohen``.
- bug:`1637` (via :issue:`1599`) Raise `SSHException` explicitly when blank
- bug:`1637` (via :issue:`1599`) Raise `SSHException` explicitly when blank
private key data is loaded, instead of the natural result of ``IndexError``.
private key data is loaded, instead of the natural result of ``IndexError``.
This should help more bits of Paramiko or Paramiko-adjacent codebases to
This should help more bits of Paramiko or Paramiko-adjacent codebases to
...
...
This diff is collapsed.
Click to expand it.
tests/test_client.py
+
18
−
0
View file @
7c97063c
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
import
weakref
import
weakref
from
tempfile
import
mkstemp
from
tempfile
import
mkstemp
import
pytest
from
pytest_relaxed
import
raises
from
pytest_relaxed
import
raises
from
mock
import
patch
,
Mock
from
mock
import
patch
,
Mock
...
@@ -462,6 +463,23 @@
...
@@ -462,6 +463,23 @@
assert
p
()
is
None
assert
p
()
is
None
@patch
(
"
paramiko.client.socket.socket
"
)
@patch
(
"
paramiko.client.socket.getaddrinfo
"
)
def
test_closes_socket_on_socket_errors
(
self
,
getaddrinfo
,
mocket
):
getaddrinfo
.
return_value
=
(
(
"
irrelevant
"
,
None
,
None
,
None
,
"
whatever
"
),
)
class
SocksToBeYou
(
socket
.
error
):
pass
my_socket
=
mocket
.
return_value
my_socket
.
connect
.
side_effect
=
SocksToBeYou
client
=
SSHClient
()
with
pytest
.
raises
(
SocksToBeYou
):
client
.
connect
(
hostname
=
"
nope
"
)
my_socket
.
close
.
assert_called_once_with
()
def
test_client_can_be_used_as_context_manager
(
self
):
def
test_client_can_be_used_as_context_manager
(
self
):
"""
"""
verify that an SSHClient can be used a context manager
verify that an SSHClient can be used a context manager
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment