tomaswolf commented on code in PR #257:
URL: https://github.com/apache/mina-sshd/pull/257#discussion_r1003582623
##########
sshd-core/src/main/java/org/apache/sshd/common/io/nio2/Nio2Session.java:
##########
@@ -298,24 +300,44 @@ public Nio2Service getService() {
@Override
public void shutdownOutputStream() throws IOException {
- AsynchronousSocketChannel socket = getSocket();
- if (socket.isOpen()) {
- if (log.isDebugEnabled()) {
- log.debug("shudownOutputStream({})", this);
- }
- try {
- socket.shutdownOutput();
- } catch (ClosedChannelException e) {
- // This may get called on a Channel EOF in TCP/IP port
forwarding. But reading and writing run
- // asynchronously, so it is possible that the socket channel
is actually closed here and the producer
- // that wrote into this channel has already disconnected.
- //
- // As this is asynchronous, there is a race condition here.
The isOpen() test above does not guarantee
- // that the socket channel is indeed open when we call
shutdownOutput().
- //
- // In any case it's safe here to ignore this exception as
we're trying to shut down an external end
- // of a TCP/IP port forwarding.
+ if (outputShutDown.compareAndSet(false, true)) {
+ // Schedule a "shut down the output stream" fake write packet with
a null buffer. Let already pending writes
+ // finish first.
+ Nio2DefaultIoWriteFuture future = new
Nio2DefaultIoWriteFuture("shutdown-" + getRemoteAddress(), null, null);
+ writes.add(future);
+ startWriting();
+ }
+ }
+
+ protected void doShutdownOutputStream(Nio2DefaultIoWriteFuture future,
AsynchronousSocketChannel socket)
+ throws IOException {
+ try {
+ if (socket.isOpen()) {
+ if (log.isDebugEnabled()) {
+ log.debug("doShutdownOutputStream({})", this);
+ }
+ try {
+ socket.shutdownOutput();
+ } catch (ClosedChannelException e) {
+ // This may get called on a Channel EOF in TCP/IP port
forwarding. But reading and writing run
Review Comment:
Done.
--
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]