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

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

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Tue, 28 Apr 2009 12:49:46 +0000

Bugs item #1860776, was opened at 2007-12-30 06:03
Message generated for change (Comment added) made by bagder
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: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: jls (apjenkins)
Assigned to: Daniel Stenberg (bagder)
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.

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

>Comment By: Daniel Stenberg (bagder)
Date: 2009-04-28 14:49

Message:
Thanks for telling, case is closed!

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

Comment By: jls (apjenkins)
Date: 2009-04-15 17:01

Message:
I just tried my test program with version libssh2 1.1 on OS X 10.5.6, and
the bug seems to be fixed. Thank you.

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

Comment By: Daniel Stenberg (bagder)
Date: 2009-04-15 09:10

Message:
Does this still happen with version 1.1?

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

Comment By: jls (apjenkins)
Date: 2007-12-30 19:44

Message:
Logged In: YES
user_id=996635
Originator: YES

A workaround for this problem seems to be to use libssh2_poll to wait for
there to be std or extended data on a channel, and only call
libssh2_channel_read_ex on a channel stream if libssh2_poll indicates there
is data to be read.

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

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

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2009-04-28