You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue that originates from the usage of dealloc to close and release sessions.
The code in dealloc calls c_ssh2.libssh2_session_disconnect(self._session, b"end") c_ssh2.libssh2_session_free(self._session)
In session disconnect a message is sent to the other side singling the disconnect. But by the time this function is called (dealloc is called at some point after the object is not used any more) the underlaying socket might have been closed and libssh2 will return and error . Worst yet is that the fileno gets reused for another connection and the message will be sent to a different peer (this happened to me).
I changed the API for session to include a release function. I also removed the free from channel as it shouldn't be called if the session has been release.
see: https://github.com/eliwe/ssh2-python
I didn't send a pull request as its not a proper fix (it does solve my immediate problem).
I didn't write sample code to recreate the issue as its not 100 reproducible.
The text was updated successfully, but these errors were encountered:
Interesting, yes, had not considered that the file descriptor may have been reused by the time the session object is deallocated. Disconnecting returning an error is ok, hence why return code is not checked, and that was really only done in case session.disconnect was not called. But since it can cause an issue, it should be removed.
If you want to make a PR with the disconnect line removed I'm happy to review.
Channel free should not be removed, however. That's a memory leak. Channel is guaranteed to be deallocated safely, before session, since it holds a reference to the session object it was spawned from. See open_session code. It would be obvious if it was being freed after session - that would cause a segfault.
Hi,
I have an issue that originates from the usage of dealloc to close and release sessions.
The code in dealloc calls
c_ssh2.libssh2_session_disconnect(self._session, b"end") c_ssh2.libssh2_session_free(self._session)
In session disconnect a message is sent to the other side singling the disconnect. But by the time this function is called (dealloc is called at some point after the object is not used any more) the underlaying socket might have been closed and libssh2 will return and error . Worst yet is that the fileno gets reused for another connection and the message will be sent to a different peer (this happened to me).
I changed the API for session to include a release function. I also removed the free from channel as it shouldn't be called if the session has been release.
see:
https://github.com/eliwe/ssh2-python
I didn't send a pull request as its not a proper fix (it does solve my immediate problem).
I didn't write sample code to recreate the issue as its not 100 reproducible.
The text was updated successfully, but these errors were encountered: