Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous implementation would always reset the window to the maximum size when it had dropped to below half the maximum size.
This was wrong and defeated the purpose of having a window. The window size is reduced upon reception of the data, and incremented when the reader from the channel has read some data. With a slow reader and a fast sender, the window would be opened fully even if the reader had not read the previously accumulated data. As a result, internal buffers could exceed the window size by a lot.
(Consider the very good description in ChannelDataReceiver: if the exit toll booth always tells the entry the bridge was free again, far too many cars would be let onto the bridge. With a real bridge, there'd be a gigantic traffic jam; with Apache MINA sshd, the bridge (the internal buffers) would just get longer and longer.)
Change the algorithm to increase the window size only by as much as has actually been read by the channel reader. Use the same logic as OpenSSH: send a window adjustment message when the available size is smaller than half the full window size, or if more than three full SSH packets have been buffered.
To avoid sending a window adjustment for very small amounts, require a minimum size for the adjustment (more than half a packet, or more than a tenth of the full window, or more than 16kB -- because packet size and full window size are configurable, a single minimum value is not good enough.)
If there are multiple threads reading (for instance, one from stdout and one from stderr), make sure that normally only one will cause a window adjustment to be sent.