Skip to content

Commit 2ead93d

Browse files
committed
session: un-noop disconnect
1 parent 5cdc87f commit 2ead93d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

ssh/session.pyx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,14 @@ cdef class Session:
140140
return handle_error_codes(rc, self._session)
141141

142142
def disconnect(self):
143-
"""No-op. Handled by object de-allocation."""
144-
# Due to bug in libssh that segfaults if session
145-
# is disconnected before freeing channels spawned
146-
# by that session - even if channels are closed.
147-
pass
148-
# if not c_ssh.ssh_is_connected(self._session):
149-
# return
150-
# with nogil:
151-
# c_ssh.ssh_disconnect(self._session)
143+
"""
144+
Cleanly disconnect connection. All channels left open at this point are invalidated.
145+
Interacting with their Channel objects will trigger UB.
146+
"""
147+
if not c_ssh.ssh_is_connected(self._session):
148+
return
149+
with nogil:
150+
c_ssh.ssh_disconnect(self._session)
152151

153152
def connector_new(self):
154153
cdef c_ssh.ssh_connector _connector

0 commit comments

Comments
 (0)