Skip to content

Commit fe1f81b

Browse files
channel: retry ssh_channel_open_session with SSH_AGAIN
Setting a low SSH options timeout value can lead to LibsshChannelException: Failed to open_session: [-2] Attempt to retry when this occurs.
1 parent 67fcbec commit fe1f81b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/pylibsshext/channel.pyx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ cdef class Channel:
6363

6464
if self._libssh_channel is NULL:
6565
raise MemoryError
66-
rc = libssh.ssh_channel_open_session(self._libssh_channel)
67-
66+
rc = libssh.SSH_AGAIN
67+
while rc == libssh.SSH_AGAIN:
68+
rc = libssh.ssh_channel_open_session(self._libssh_channel)
6869
if rc != libssh.SSH_OK:
6970
libssh.ssh_channel_free(self._libssh_channel)
7071
self._libssh_channel = NULL
@@ -164,7 +165,9 @@ cdef class Channel:
164165
if channel is NULL:
165166
raise MemoryError
166167

167-
rc = libssh.ssh_channel_open_session(channel)
168+
rc = libssh.SSH_AGAIN
169+
while rc == libssh.SSH_AGAIN:
170+
rc = libssh.ssh_channel_open_session(channel)
168171
if rc != libssh.SSH_OK:
169172
libssh.ssh_channel_free(channel)
170173
raise LibsshChannelException("Failed to open_session: [{0}]".format(rc))

0 commit comments

Comments
 (0)