[ https://issues.apache.org/jira/browse/SSHD-85?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16059561#comment-16059561 ]
ASF GitHub Bot commented on SSHD-85: ------------------------------------ GitHub user bkuker opened a pull request: https://github.com/apache/mina-sshd/pull/33 Tests & Candidate fix for SSHD-85. SSHD-85 is a bug that occurs on Windows where the last few bytes of data sent through a port forward can be lost when the server at the far end of the port forward sends the data and immediately closes the socket. An example of this server behavior would be HTTP 1.0 with the Connection: close header. The server sends the data, and then closes the socket to indicate that it is done sending data. The server does not send a Content-Length header or similar. This is a stupid way to do it, all modern http servers do better, but there are still old embedded systems that work this way, and it does impact my use case. The test cases include some sleeps on the client end. This seems to be a race condition that occurs possibly one time in a hundred or more, but these sleeps cause it to happen every single time. The test cases include two controls: JSCH as the client During testing I did verify that the test server did send all data to the ssh client by examining the buffers in the ssh client and seeing all of the data. I then verified that all of the data was transferred from the ssh client to the ssh server by examining the buffers in the sshd server. The sshd server does write all of that data to the socket as far as I can tell, but on Windows some still goes missing at the end! I also verified that on Local port forwards the error does occur with Apache SSHD as the client, and does NOT occur with JSCH as the client. I would like to try that the other way around with Apache SSH Client and another server, but the pickings for Java SSH servers are slim, and this one is the best! I am currently trying to understand WHY the fix (basically one line, getSocket().shutdownOutput()) fixes the problem. I am submitting this PR now in hopes that someone with a better understanding will point out why it is the correct fix and accept it. All I can say at the moment is that it works. Also includes a fix for a test in PortForwardingLoadTest which was failing for me before I started investigating. Frankly it looks like it never worked; I would guess that there was some copy-paste mistake in the past when it got updated to use try-with-resources. I am ... very motivated to get this fixed so I do not have to maintain my own private branch of sshd, so please ask questions, make suggestions, if you think I am totally crazy help me prove that I am not! You can merge this pull request into a Git repository by running: $ git pull https://github.com/bkuker/mina-sshd sshd-85 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/mina-sshd/pull/33.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #33 ---- commit e6e400b24fe5d4d6778135e1ae5e38fb8ac3631a Author: bkuker <bku...@martellotech.com> Date: 2017-06-14T12:20:41Z Tests for SSHD-85 commit fe92dc673678e66374d2a095a2299b8e60425c98 Author: bkuker <bku...@martellotech.com> Date: 2017-06-20T15:01:56Z The Fix? commit 5842c850485835a98385937df7bb74b0ca4c4889 Author: bkuker <bku...@martellotech.com> Date: 2017-06-22T13:13:57Z This test failed before my changes. It made no sense as it was. ---- > 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)