Subject: [libssh2] #263: libssh2_channel_read for exec ends unpredictably

[libssh2] #263: libssh2_channel_read for exec ends unpredictably

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Tue, 09 Apr 2013 22:26:22 -0000

#263: libssh2_channel_read for exec ends unpredictably
---------------------+--------------------
 Reporter: xtravar | Owner:
     Type: defect | Status: new
 Priority: normal | Milestone: 1.4.3
Component: API | Version: 1.4.2
 Keywords: | Blocked By:
   Blocks: |
---------------------+--------------------
 Problem: libssh2_channel_exec is returning EOF sooner than expected
 randomly

 Client Platform: iOS
 Versions tried: 1.4.3, 1.4.4-20130409

 *Tried with blocking & non-blocking
 *Piped to 'tee' to verify the process isn't ending prematurely (the file
 gets written out completely)
 *Same problem does not happen with SCP
 *Never happens on the first run of the code

 My code vaguely looks like:
 {{{
 chan = libssh2_channel_open_session(session);
 libssh2_channel_exec(chan, "convert \"test.jpg\" -quality 60 -resize 100%
 -format JPEG - 2>/dev/null | tee converttest.jpg")
 // loop until read returns 0 (eof also becomes true at this point)
 libssh2_channel_close(chan);
 }}}

 The problem happens after a few runs of the code on the same command.
 It's fairly reproducible. I have some trace output that might be useful.

 Good run:
  Conn: Allocated new channel ID#2
  Conn: Opening Channel - win 262144 pack 32768
  Socket: Sent 52/52 bytes at 0x8a9775c
  Failure Event: -37 - Would block
  Socket: Recved 52/16384 bytes to 0x8a93734+0
  Conn: Connection Established - ID: 2/1 win: 0/262144 pack: 32768/32768
  Conn: starting request(exec) on channel 2/1, message=convert "cover.jpg"
 -quality 60 -resize 100% -format JPEG -
  Socket: Sent 52/52 bytes at 0x8a9775c
  Socket: Recved 88/16384 bytes to 0x8a93734+0
  Conn: Window adjust for channel 2/1, adding 2097152 bytes, new
 window_size=2097152
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 116/16384 bytes to 0x8a93734+0
  Conn: 8192 bytes packet_add() for 2/1/0
  Conn: channel_read() got 8192 of data from 2/1/0 [ul]
  Socket: Recved 376/16384 bytes to 0x8a93734+0
  Conn: 8192 bytes packet_add() for 2/1/0
  Conn: 4096 bytes packet_add() for 2/1/0
  Conn: 851 bytes packet_add() for 2/1/0
  Conn: EOF received for channel 2/1
  Conn: Channel 2 received request type exit-status (wr 0)
  Conn: Exit status 0 received for channel 2/1
  Conn: Close received for channel 2/1
  Conn: channel_read() got 8192 of data from 2/1/0 [ul]
  Conn: channel_read() got 2048 of data from 2/1/0
  Conn: channel_read() got 2048 of data from 2/1/0 [ul]
  Conn: channel_read() got 851 of data from 2/1/0 [ul]
  Conn: Sending EOF on channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c
  Conn: Closing channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c

 Bad run:
  Conn: Allocated new channel ID#2
  Conn: Opening Channel - win 262144 pack 32768
  Socket: Sent 52/52 bytes at 0x8a9775c
  Failure Event: -37 - Would block
  Socket: Recved 52/16384 bytes to 0x8a93734+0
  Conn: Connection Established - ID: 2/1 win: 0/262144 pack: 32768/32768
  Conn: starting request(exec) on channel 2/1, message=convert "cover.jpg"
 -quality 60 -resize 100% -format JPEG -
  Socket: Sent 52/52 bytes at 0x8a9775c
  Socket: Recved 88/16384 bytes to 0x8a93734+0
  Conn: Window adjust for channel 2/1, adding 2097152 bytes, new
 window_size=2097152
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 116/16384 bytes to 0x8a93734+0
  Conn: 8007 bytes packet_add() for 2/1/0
  Conn: channel_read() got 8007 of data from 2/1/0 [ul]
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 116/16384 bytes to 0x8a93734+0
  Failure Event: -37 - would block
  Conn: channel_read() wants 10240 bytes from channel 2/1 stream #0
  Socket: Recved 82/16384 bytes to 0x8a93734+0
  Conn: 4096 bytes packet_add() for 2/1/0
  Conn: channel_read() got 4096 of data from 2/1/0 [ul]
  Socket: Recved 176/16384 bytes to 0x8a93734+0
  Conn: 851 bytes packet_add() for 2/1/0
  Conn: Channel 2 received request type exit-status (wr 0)
  Conn: Exit status 0 received for channel 2/1
  Conn: EOF received for channel 2/1
  Conn: Close received for channel 2/1
  Conn: channel_read() got 851 of data from 2/1/0 [ul]
  Conn: Sending EOF on channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c
  Conn: Closing channel 2/1
  Socket: Sent 36/36 bytes at 0x8a9775c

-- 
Ticket URL: <https://trac.libssh2.org/ticket/263>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-04-10