[
https://issues.apache.org/jira/browse/SSHD-85?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16052959#comment-16052959
]
Bill Kuker commented on SSHD-85:
--------------------------------
The behavior of the server is simplified, but more or less identical to, an
http 1.0 server with connection: close in the header. It writes the bytes and
then closes the connection.
Also my test fails all the time in Windows, but I have NOT gotten it to fail
under linux. Can I ask what OS you have been running under? I am still working
to try to reproduce under Linux. Experience tells me that code that is very
broken on one OS is sometimes only very subtly broken on another; In 2010 when
I first reported this bug less than one HTTP 1.0 request in a hundred failed
when made via apache sshd...
The problem is that the server writes bytes and then closes, sshd gets those
bytes and then sends them to the client. If the socket sshd is writing to is
not ready to be written to when it comes time to pass along those bytes they
are buffered in sshd. When it becomes ready to write sshd writes them... All
good... BUT if the server closes the connection before sshd has written the
bytes it has buffered [because the socket is not ready to be written to] sshd
turns around and closes the socket to the client, having never written those
bytes.
So the last part of the data is still in a buffer in sshd user space, read from
the server, not written to the port forward client, when the server closes the
connection... Sshd then closes the other socket, when what it needs to do is
wait for the socket to be writable, write the bytes from it's buffer, then
close it... Clear as mud?
> Port Forward closes connection before all bytes are sent
> --------------------------------------------------------
>
> Key: SSHD-85
> URL: https://issues.apache.org/jira/browse/SSHD-85
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 0.2.0, 1.4.0, 1.6.0
> Environment: Windows or Linux, JSCH Client
> Reporter: Bill Kuker
> Assignee: Guillaume Nodet
> Attachments: MINA-Port-Forward.txt, SSHD-85_testcase.txt
>
>
> When I am forwarding connections from a Client to a port on the SSH Server
> through the SSH Client to a Remote Server on the SSH Client network:
> Client --(a)---> SSH Server <===[ssh]===> SSH Client --(b)--> Remote Server
> if the Remote Server sends some bytes and immediately closes the connection
> (b) to the SSH Client the SSH Server will close the connection (a) to the
> client before all of those bytes are sent to the SSH Client.
> This is probably a race condition. If I run one connection at a time it works
> 99% of the time, but if I use a load generator (a completely separate
> process) to max out all 4 cores I can make it fail (I do not get all the
> bytes from Remote Server at Client) 99% of the time. Also by running about
> 100 simultaneous requests I get maybe a 20% failure rate.
> If the Remote Server is something like Telnet (Open for a while, user closes
> connection) everything seems fine, but the the Remote Server is a web server
> with keep alive disabled, and many small requests are made, many images,
> htmls, css are truncated.
> Sorry I can't be more precise with this, but I hope anyone else having a
> similar trouble can help fill out this bug with details.
> *Update in 2017*
> I have provided a maven project with a unit test that has a 100% failure rate
> on my desktop without resorting to creating artificial load. It is a lot
> simpler:
> https://github.com/bkuker/sshd-85
> https://github.com/bkuker/sshd-85/blob/master/src/main/java/com/billkuker/sshd/sshd85/TheTest.java
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)