Skip to content

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

Open
yo-bur wants to merge 1 commit intomarianafranco:masterfrom
yo-bur:bugfix/retry-writing-on-again-error
Open

Try writing again to the channel if LIBSSH2_ERROR_EAGAIN is returned.#3
yo-bur wants to merge 1 commit intomarianafranco:masterfrom
yo-bur:bugfix/retry-writing-on-again-error

Conversation

@yo-bur
Copy link
Copy Markdown

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

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

Copy link
Copy Markdown
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! :)

Comment thread libssh2-tunnel-example.c
do {
i = libssh2_channel_write(channel, buf, len);
i = LIBSSH2_ERROR_EAGAIN;
while (i == LIBSSH2_ERROR_EAGAIN) {
Copy link
Copy Markdown
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