Subject: [libssh2] [ libssh2-Bugs-1860776 ] non-blocking, normal and stderr stream read bug

[libssh2] [ libssh2-Bugs-1860776 ] non-blocking, normal and stderr stream read bug

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Sat, 29 Dec 2007 21:03:11 -0800

Bugs item #1860776, was opened at 2007-12-30 00:03
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1860776&group_id=125852

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: misc
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: jls (apjenkins)
Assigned to: Nobody/Anonymous (nobody)
Summary: non-blocking, normal and stderr stream read bug

Initial Comment:
I have found a bug in libssh2 0.18, where if I have a channel in non-blocking mode and I alternate reading from the standard and error streams of the channel, then no data is ever read; that is channel_read_ex always returns LIBSSH2_ERROR_EAGAIN, even though the remote process is sending data.

Basically, if you have a channel in non-blocking mode, then if you have code like this:

while (stillSomeDataToRead) {
  // read from stderr stream
  nRead = libssh2_channel_read_stderr(
    channel, buf, bufsize);
  // check for errors, handle input

  // read from std
  nRead = libssh2_channel_read(
    channel, buf, bufsize);
  // check for errors, handle input
}

then it often is the case that the channel_reads just keep returning LIBSSH2_ERROR_EAGAIN (-37) forever. If I comment out the libssh2_channel_read_stderr statement, then it does eventually read data from the channel's stdout stream. So it seems that somehow, calling libssh2_channel_read_stderr prevents libssh2_channel_read from ever receiving any data, even though channel_read_stderr always just returns EAGAIN.
  

I have attached a program which demonstrates the bug. I have tried this on an i386 Linux machine, and an Intel Mac running Leopard, and the bug occurs in both cases. Occasionally the program works correctly so you may need to run it several times to see the problem. If the program works correctly, then it will output

...
channel_read err returned -37
channel_read returned -37
channel_read err returned -37
channel_read returned -37
channel_read err returned -37
channel_read returned 4096
  
If the failure occurs, then the "returned 4096" line never comes, and the reads just keep returning -37 forever.

Run the program as
  ./libssh2hang2 YOUPASSWORD
The program will try to establish a connection to the localhost and log in using password auth. Pass your password as the first cmdline argument. It will then exec the "yes" command, which just outputs an endless stream of characters, put the channel into non-blocking mode, and then keep reading until it's read at least 4096 bytes. If you disable the libssh2_channel_read_stderr statement, then it always works.

Please let me know if you need any more information.

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1860776&group_id=125852

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-12-30