[SSHD-1307] Make Nio2Session.shutdownOutputStream() asynchronous #257
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.
Nio2Session.shutdownOutputStream() can be invoked while there are still writes in progress. The output is shut down in TCP/IP port forwarding to propagate an SSH_MSG_CHANNEL_EOF from the channel to whatever is on the other side of the forwarded port; see SSHD-1055. However, writing through the socket is asynchronous, so a channel may get the following sequence of events:
If (5) shuts down the output immediately but the write request from (2) has not been written yet, that write attempt will fail with a ClosedChannelException.
The output stream on the socket should not be shut down immediately but only once already pending writes have been done. This is already the case with the MINA and Netty transport back-ends, which only schedule a shutdown request on their write queue.
Implement the same for the NIO2 transport. A write future with a null buffer signifies a shutdown request; true write requests always have a non-null buffer. Make shutdownOutputStream() only enqueue such a shutdown request on the session's write queue; the output will be shut down once startWriting() pops this shutdown request from the write queue.