[jira] [Work logged] (SSHD-1307) Nio2Session.shutdownOutput() should wait for writes in progress

2022-10-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/SSHD-1307?focusedWorklogId=821134=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-821134
 ]

ASF GitHub Bot logged work on SSHD-1307:


Author: ASF GitHub Bot
Created on: 27/Oct/22 18:32
Start Date: 27/Oct/22 18:32
Worklog Time Spent: 10m 
  Work Description: tomaswolf commented on PR #257:
URL: https://github.com/apache/mina-sshd/pull/257#issuecomment-1293914238

   Answer is on 
[SSHD-1307](https://issues.apache.org/jira/browse/SSHD-1307?focusedCommentId=17625229=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17625229),
 where you had asked the same.




Issue Time Tracking
---

Worklog Id: (was: 821134)
Time Spent: 1h  (was: 50m)

> Nio2Session.shutdownOutput() should wait for writes in progress
> ---
>
> Key: SSHD-1307
> URL: https://issues.apache.org/jira/browse/SSHD-1307
> Project: MINA SSHD
>  Issue Type: Bug
>Affects Versions: 2.9.1
>Reporter: Thomas Wolf
>Assignee: Thomas Wolf
>Priority: Major
> Fix For: 2.9.2
>
>  Time Spent: 1h
>  Remaining Estimate: 0h
>
> Split out from 
> [SSHD-1055|https://issues.apache.org/jira/browse/SSHD-1055?focusedCommentId=17621354=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17621354]:
> I am currently experiencing an exception that appears to be related to the 
> use of the serverSession.shudownOutputStream(); in the 
> TcpIpClientChannel.handleEOF method.
> My context is the following
>  * Apache Mina sshd client version 2.9.1 on the local side.
>  * OpenSSH 5.9 on the remote server side.
>  * Local port forwarding port 9000 to remote localhost:8080
>  * The error occurs on the Apache Mina sshd client side.
> I intermittently take exceptions on URL connections that are completed and 
> they have received the last of the data and is processing the 
> SSH_MSG_CHANNEL_EOF
> Any ideas or thoughts would be appreciated.
> {code:java}
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=999
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 999 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=2
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 2 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=115
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 115 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleEof(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_EOF
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> shudownOutputStream(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027])
> 09:16:42.875 [sshd-SshClient[477424ca]-nio2-thread-6] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> handleWriteCycleFailure(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027]) failed (ClosedChannelException) to write 115 bytes 
> at write cycle=17 afer 987500 nanos: null
> 09:16:42.875 [sshd-SshClient[477424ca]-nio2-thread-6] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> exceptionCaught(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> caught ClosedChannelException[null] - calling handler
> 09:16:42.879 [sshd-SshClient[477424ca]-nio2-thread-4] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> handleReadCycleCompletion(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027]) Socket has been disconnected (result=-1), closing 
> IoSession now
> 09:16:42.879 [sshd-SshClient[477424ca]-nio2-thread-4] DEBUG 
> 

[jira] [Work logged] (SSHD-1307) Nio2Session.shutdownOutput() should wait for writes in progress

2022-10-27 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/SSHD-1307?focusedWorklogId=821103=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-821103
 ]

ASF GitHub Bot logged work on SSHD-1307:


Author: ASF GitHub Bot
Created on: 27/Oct/22 17:38
Start Date: 27/Oct/22 17:38
Worklog Time Spent: 10m 
  Work Description: AlexanderAmador commented on PR #257:
URL: https://github.com/apache/mina-sshd/pull/257#issuecomment-1293857850

   I am interested in acquiring this fix in a release. I saw a comment that 
your next release may be 2.10.0. Do you have an ETA on that release ? 




Issue Time Tracking
---

Worklog Id: (was: 821103)
Time Spent: 50m  (was: 40m)

> Nio2Session.shutdownOutput() should wait for writes in progress
> ---
>
> Key: SSHD-1307
> URL: https://issues.apache.org/jira/browse/SSHD-1307
> Project: MINA SSHD
>  Issue Type: Bug
>Affects Versions: 2.9.1
>Reporter: Thomas Wolf
>Assignee: Thomas Wolf
>Priority: Major
> Fix For: 2.9.2
>
>  Time Spent: 50m
>  Remaining Estimate: 0h
>
> Split out from 
> [SSHD-1055|https://issues.apache.org/jira/browse/SSHD-1055?focusedCommentId=17621354=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17621354]:
> I am currently experiencing an exception that appears to be related to the 
> use of the serverSession.shudownOutputStream(); in the 
> TcpIpClientChannel.handleEOF method.
> My context is the following
>  * Apache Mina sshd client version 2.9.1 on the local side.
>  * OpenSSH 5.9 on the remote server side.
>  * Local port forwarding port 9000 to remote localhost:8080
>  * The error occurs on the Apache Mina sshd client side.
> I intermittently take exceptions on URL connections that are completed and 
> they have received the last of the data and is processing the 
> SSH_MSG_CHANNEL_EOF
> Any ideas or thoughts would be appreciated.
> {code:java}
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=999
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 999 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=2
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 2 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=115
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 115 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleEof(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_EOF
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> shudownOutputStream(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027])
> 09:16:42.875 [sshd-SshClient[477424ca]-nio2-thread-6] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> handleWriteCycleFailure(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027]) failed (ClosedChannelException) to write 115 bytes 
> at write cycle=17 afer 987500 nanos: null
> 09:16:42.875 [sshd-SshClient[477424ca]-nio2-thread-6] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> exceptionCaught(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> caught ClosedChannelException[null] - calling handler
> 09:16:42.879 [sshd-SshClient[477424ca]-nio2-thread-4] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> handleReadCycleCompletion(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027]) Socket has been disconnected (result=-1), closing 
> IoSession now
> 09:16:42.879 [sshd-SshClient[477424ca]-nio2-thread-4] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> close(Nio2Session[local=/127.0.0.1:9000, 

[jira] [Work logged] (SSHD-1307) Nio2Session.shutdownOutput() should wait for writes in progress

2022-10-24 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/SSHD-1307?focusedWorklogId=819817=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-819817
 ]

ASF GitHub Bot logged work on SSHD-1307:


Author: ASF GitHub Bot
Created on: 24/Oct/22 19:12
Start Date: 24/Oct/22 19:12
Worklog Time Spent: 10m 
  Work Description: tomaswolf merged PR #257:
URL: https://github.com/apache/mina-sshd/pull/257




Issue Time Tracking
---

Worklog Id: (was: 819817)
Time Spent: 40m  (was: 0.5h)

> Nio2Session.shutdownOutput() should wait for writes in progress
> ---
>
> Key: SSHD-1307
> URL: https://issues.apache.org/jira/browse/SSHD-1307
> Project: MINA SSHD
>  Issue Type: Bug
>Affects Versions: 2.9.1
>Reporter: Thomas Wolf
>Assignee: Thomas Wolf
>Priority: Major
>  Time Spent: 40m
>  Remaining Estimate: 0h
>
> Split out from 
> [SSHD-1055|https://issues.apache.org/jira/browse/SSHD-1055?focusedCommentId=17621354=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17621354]:
> I am currently experiencing an exception that appears to be related to the 
> use of the serverSession.shudownOutputStream(); in the 
> TcpIpClientChannel.handleEOF method.
> My context is the following
>  * Apache Mina sshd client version 2.9.1 on the local side.
>  * OpenSSH 5.9 on the remote server side.
>  * Local port forwarding port 9000 to remote localhost:8080
>  * The error occurs on the Apache Mina sshd client side.
> I intermittently take exceptions on URL connections that are completed and 
> they have received the last of the data and is processing the 
> SSH_MSG_CHANNEL_EOF
> Any ideas or thoughts would be appreciated.
> {code:java}
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=999
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 999 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=2
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 2 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=115
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 115 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleEof(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_EOF
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> shudownOutputStream(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027])
> 09:16:42.875 [sshd-SshClient[477424ca]-nio2-thread-6] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> handleWriteCycleFailure(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027]) failed (ClosedChannelException) to write 115 bytes 
> at write cycle=17 afer 987500 nanos: null
> 09:16:42.875 [sshd-SshClient[477424ca]-nio2-thread-6] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> exceptionCaught(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> caught ClosedChannelException[null] - calling handler
> 09:16:42.879 [sshd-SshClient[477424ca]-nio2-thread-4] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> handleReadCycleCompletion(Nio2Session[local=/127.0.0.1:9000, 
> remote=/127.0.0.1:62027]) Socket has been disconnected (result=-1), closing 
> IoSession now
> 09:16:42.879 [sshd-SshClient[477424ca]-nio2-thread-4] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> close(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) Closing 
> immediately
> 09:16:42.879 [sshd-SshClient[477424ca]-nio2-thread-4] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> doCloseImmediately(Nio2Session[local=/127.0.0.1:9000, 
> 

[jira] [Work logged] (SSHD-1307) Nio2Session.shutdownOutput() should wait for writes in progress

2022-10-24 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/SSHD-1307?focusedWorklogId=819792=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-819792
 ]

ASF GitHub Bot logged work on SSHD-1307:


Author: ASF GitHub Bot
Created on: 24/Oct/22 17:36
Start Date: 24/Oct/22 17:36
Worklog Time Spent: 10m 
  Work Description: 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.





Issue Time Tracking
---

Worklog Id: (was: 819792)
Time Spent: 0.5h  (was: 20m)

> Nio2Session.shutdownOutput() should wait for writes in progress
> ---
>
> Key: SSHD-1307
> URL: https://issues.apache.org/jira/browse/SSHD-1307
> Project: MINA SSHD
>  Issue Type: Bug
>Affects Versions: 2.9.1
>Reporter: Thomas Wolf
>Assignee: Thomas Wolf
>Priority: Major
>  Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Split out from 
> [SSHD-1055|https://issues.apache.org/jira/browse/SSHD-1055?focusedCommentId=17621354=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17621354]:
> I am currently experiencing an exception that appears to be related to the 
> use of the serverSession.shudownOutputStream(); in the 
> TcpIpClientChannel.handleEOF method.
> My context is the following
>  * Apache Mina sshd client version 2.9.1 on the local side.
>  * OpenSSH 5.9 on the remote server side.
>  * Local port forwarding port 9000 to remote localhost:8080
>  * The error occurs on the Apache Mina sshd client side.
> I intermittently take exceptions on URL connections that are completed and 
> they have received the last of the data and is processing the 
> SSH_MSG_CHANNEL_EOF
> Any ideas or thoughts would be appreciated.
> {code:java}
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=999
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 999 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA 

[jira] [Work logged] (SSHD-1307) Nio2Session.shutdownOutput() should wait for writes in progress

2022-10-24 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/SSHD-1307?focusedWorklogId=819786=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-819786
 ]

ASF GitHub Bot logged work on SSHD-1307:


Author: ASF GitHub Bot
Created on: 24/Oct/22 17:16
Start Date: 24/Oct/22 17:16
Worklog Time Spent: 10m 
  Work Description: lgoldstein commented on code in PR #257:
URL: https://github.com/apache/mina-sshd/pull/257#discussion_r1003563357


##
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:
   I think we should log this exception as DEBUG or TRACE level so that we can 
tell if it happened.





Issue Time Tracking
---

Worklog Id: (was: 819786)
Time Spent: 20m  (was: 10m)

> Nio2Session.shutdownOutput() should wait for writes in progress
> ---
>
> Key: SSHD-1307
> URL: https://issues.apache.org/jira/browse/SSHD-1307
> Project: MINA SSHD
>  Issue Type: Bug
>Affects Versions: 2.9.1
>Reporter: Thomas Wolf
>Assignee: Thomas Wolf
>Priority: Major
>  Time Spent: 20m
>  Remaining Estimate: 0h
>
> Split out from 
> [SSHD-1055|https://issues.apache.org/jira/browse/SSHD-1055?focusedCommentId=17621354=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17621354]:
> I am currently experiencing an exception that appears to be related to the 
> use of the serverSession.shudownOutputStream(); in the 
> TcpIpClientChannel.handleEOF method.
> My context is the following
>  * Apache Mina sshd client version 2.9.1 on the local side.
>  * OpenSSH 5.9 on the remote server side.
>  * Local port forwarding port 9000 to remote localhost:8080
>  * The error occurs on the Apache Mina sshd client side.
> I intermittently take exceptions on URL connections that are completed and 
> they have received the last of the data and is processing the 
> SSH_MSG_CHANNEL_EOF
> Any ideas or thoughts would be appreciated.
> {code:java}
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=999
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 999 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> 

[jira] [Work logged] (SSHD-1307) Nio2Session.shutdownOutput() should wait for writes in progress

2022-10-22 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/SSHD-1307?focusedWorklogId=819382=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-819382
 ]

ASF GitHub Bot logged work on SSHD-1307:


Author: ASF GitHub Bot
Created on: 22/Oct/22 21:41
Start Date: 22/Oct/22 21:41
Worklog Time Spent: 10m 
  Work Description: tomaswolf opened a new pull request, #257:
URL: https://github.com/apache/mina-sshd/pull/257

   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:
   
   1. receive last SSH_MSG_CHANNEL_DATA
   2. Nio2Session.writeBuffer() enqueues the write request
   3. SSH_MSG_CHANNEL_DATA handling completes
   4. receive SSH_MSG_CHANNEL_EOF
   5. call Nio2Session.shutdownOutputStream()
   
   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.




Issue Time Tracking
---

Worklog Id: (was: 819382)
Remaining Estimate: 0h
Time Spent: 10m

> Nio2Session.shutdownOutput() should wait for writes in progress
> ---
>
> Key: SSHD-1307
> URL: https://issues.apache.org/jira/browse/SSHD-1307
> Project: MINA SSHD
>  Issue Type: Bug
>Affects Versions: 2.9.1
>Reporter: Thomas Wolf
>Assignee: Thomas Wolf
>Priority: Major
>  Time Spent: 10m
>  Remaining Estimate: 0h
>
> Split out from 
> [SSHD-1055|https://issues.apache.org/jira/browse/SSHD-1055?focusedCommentId=17621354=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17621354]:
> I am currently experiencing an exception that appears to be related to the 
> use of the serverSession.shudownOutputStream(); in the 
> TcpIpClientChannel.handleEOF method.
> My context is the following
>  * Apache Mina sshd client version 2.9.1 on the local side.
>  * OpenSSH 5.9 on the remote server side.
>  * Local port forwarding port 9000 to remote localhost:8080
>  * The error occurs on the Apache Mina sshd client side.
> I intermittently take exceptions on URL connections that are completed and 
> they have received the last of the data and is processing the 
> SSH_MSG_CHANNEL_EOF
> Any ideas or thoughts would be appreciated.
> {code:java}
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=999
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 999 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=2
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 2 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleData(TcpipClientChannel[id=71, 
> recipient=2]-ClientSessionImpl[r...@elib17.us.oracle.com/10.80.104.97:22]) 
> SSH_MSG_CHANNEL_DATA len=115
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.io.nio2.Nio2Session - 
> writeBuffer(Nio2Session[local=/127.0.0.1:9000, remote=/127.0.0.1:62027]) 
> writing 115 bytes
> 09:16:42.873 [sshd-SshClient[477424ca]-nio2-thread-8] DEBUG 
> org.apache.sshd.common.forward.TcpipClientChannel - 
> handleEof(TcpipClientChannel[id=71, 
>