Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try writing again to the channel if LIBSSH2_ERROR_EAGAIN is returned. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yo-bur
Copy link

@yo-bur yo-bur commented Feb 16, 2019

If LIBSSH2_ERROR_EAGAIN is returned for libssh2_channel_write, retry writing the data.

Copy link
Owner

@marianafranco marianafranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! :)

@@ -106,7 +106,10 @@ int forward_tunnel(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel) {
}
wr = 0;
do {
i = libssh2_channel_write(channel, buf, len);
i = LIBSSH2_ERROR_EAGAIN;
while (i == LIBSSH2_ERROR_EAGAIN) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can cause an infinite loop, blocking the tunnel on write.
The correct way to handle this is to check if the socket is alive before sending it again: https://stackoverflow.com/a/9811061/2052076

Some code examples that I found:
https://github.com/allisrc/libgit2-allisrc/blob/62ab0e1fc2a471db960b0bd881aab116b350a961/src/transports/ssh.c#L266

https://github.com/u35s/xtools/blob/99fe76fffb5d893573b1aa21e8032dc5385c2837/src/common/ssh2_client.cc#L185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants