tomaswolf commented on issue #791:
URL: https://github.com/apache/mina-sshd/issues/791#issuecomment-3141014489
Thinking more about this: it appears your server does not close the channel
properly. This is normally a handshake, but if the server doesn't follow that
protocol, weird things may happen. When a server closes a channel, this is
normally what gets sent:
```
msg# client server
x <-- SSH_MSG_CHANNEL_EOF ---
x+1 <-- SSH_MSG_CHANNEL_CLOSE ---
x+2 --- data or window_adjust -->
... as much as still needed...
x+n --- data or window_adjust -->
x+n+1 --- SSH_MSG_CHANNEL_CLOSE -->
closes closes
channel channel
```
Now, if your server doesn't wait for message `x+n+1` (the CLOSE confirmation
from the client) but closes the connection right after message `x+1`, then the
client would get at `x+2` or any later message the "broken pipe" exception. Now
assume we have just before that
```
x-2 <-- SSH_MSG_CHANNEL_DATA ---
x-1 <-- SSH_MSG_CHANNEL_DATA ---
```
and the client is a bit slow in handling these data messages, after message
`x-2` a window adjust must be sent from the client to the server, and the
server doesn't behave well and doesn't wait for the client's CLOSE. Then we get
```
x-2 <-- SSH_MSG_CHANNEL_DATA ---
in buffer x-1 <-- SSH_MSG_CHANNEL_DATA ---
in buffer x <-- SSH_MSG_CHANNEL_EOF ---
in buffer x+1 <-- SSH_MSG_CHANNEL_CLOSE ---
server closes connection
x+2 --- window_adjust -->. !fails with broken pipe
client handles exception,
closes channel & session
```
I would have to check why that client channel still tries to read the
buffered `x-1`message (obviously it does, but the channel is gone: that's the
`DefaultUnknownChannelReferenceHandler` stuff you showed in the logs above).
It is, however, unclear what we could do in this case. I'd expect the
channel to not even read the buffered `x-1` message. But even if it does, the
client doesn't know yet that it's the last data message on that channel (it
hasn't seen the EOF or CLOSE from the server yet), so I don't know how to
distinguish this from a connection failure somewhere in the middle of a data
transfer.
If we could create a Java-only test case with a server that behaves in this
way we could examine what exactly happens in the client in this case, and then
maybe find a solution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]