I think I now know under which rare circumstances this happens and it is a bug in libssh2.
I can simulate it with (e.g. a packet is not completly written and the attempt to write the rest creates EAGAIN): In below simulation the 10 packet is reduced by 30 bytes and the attempt to write the 30 bytes later creates an EAGAIN. --- src/channel.c 2009-02-07 14:52:54.000000000 +0000 +++ src/channel_sim.c 2009-02-07 14:52:28.000000000 +0000 @@ -1733,6 +1733,7 @@ libssh2_channel_write_ex(LIBSSH2_CHANNEL * channel, int stream_id, const char *buf, size_t buflen) { + static count=0; LIBSSH2_SESSION *session = channel->session; libssh2pack_t rc; @@ -1772,10 +1773,15 @@ } while (buflen > 0) { + count++; if (channel->write_state == libssh2_NB_state_allocated) { + if (count == 10) { + channel->write_bufwrite = buflen-30; + channel->write_s = channel->write_packet; + } else { channel->write_bufwrite = buflen; channel->write_s = channel->write_packet; - + } *(channel->write_s++) = stream_id ? SSH_MSG_CHANNEL_EXTENDED_DATA : SSH_MSG_CHANNEL_DATA; @@ -1842,9 +1848,13 @@ } if (channel->write_state == libssh2_NB_state_created) { + if (count == 11) { + rc = PACKET_EAGAIN; + } else { rc = libssh2_packet_write(session, channel->write_packet, channel->write_s - channel->write_packet); + } if (rc == PACKET_EAGAIN) { _libssh2_debug(session, LIBSSH2_DBG_CONN, "libssh2_packet_write returned EAGAIN"); My solution to this is: --- src/channel.c 2009-02-06 23:57:47.000000000 +0000 +++ src/channel_new.c 2009-02-06 23:57:42.000000000 +0000 @@ -1771,6 +1771,7 @@ channel->write_state = libssh2_NB_state_allocated; } + buflen -= channel->write_bufwrote; while (buflen > 0) { if (channel->write_state == libssh2_NB_state_allocated) { channel->write_bufwrite = buflen; Regards Markus ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ libssh2-devel mailing list libssh2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libssh2-devel