Skip to content

NPE in ChannelDirectTcpip when used with Streaming.Async #626

@ezhaka

Description

@ezhaka

Version

2.14.0

Bug description

I'm trying to use Streaming.Async together with ChannelDirectTcpip:

val channel = session.createDirectTcpipChannel(localAddress, remoteAddress)
channel.streaming = Streaming.Async
channel.open().verify(10, TimeUnit.SECONDS)

// writing something to the in channel works correctly
channel.asyncIn.writeBuffer(ByteArrayBuffer(byteArray))

// ...but when I try to read output, it throws NPE
channel.asyncOut.read(outBuffer)

Actual behavior

NPE is the following:

java.lang.NullPointerException: null
	at org.apache.sshd.client.channel.ChannelDirectTcpip.doWriteData(ChannelDirectTcpip.java:119)
	at org.apache.sshd.common.channel.AbstractChannel.handleData(AbstractChannel.java:845)
	at org.apache.sshd.common.session.helpers.AbstractConnectionService.channelData(AbstractConnectionService.java:585)
	at org.apache.sshd.common.session.helpers.AbstractConnectionService.process(AbstractConnectionService.java:466)
	at org.apache.sshd.common.session.helpers.CurrentService.process(CurrentService.java:109)
	at org.apache.sshd.common.session.helpers.AbstractSession.doHandleMessage(AbstractSession.java:625)
	at org.apache.sshd.common.session.helpers.AbstractSession.lambda$handleMessage$0(AbstractSession.java:546)
	at org.apache.sshd.common.util.threads.ThreadUtils.runAsInternal(ThreadUtils.java:68)
	at org.apache.sshd.common.session.helpers.AbstractSession.handleMessage(AbstractSession.java:545)
	at org.apache.sshd.common.session.helpers.AbstractSession.decode(AbstractSession.java:1729)
	at org.apache.sshd.common.session.helpers.AbstractSession.messageReceived(AbstractSession.java:506)
	at org.apache.sshd.common.session.helpers.AbstractSessionIoHandler.messageReceived(AbstractSessionIoHandler.java:64)
	at org.apache.sshd.common.io.nio2.Nio2Session.handleReadCycleCompletion(Nio2Session.java:409)
	at org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:382)
	at org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:377)
	at org.apache.sshd.common.io.nio2.Nio2CompletionHandler.lambda$completed$0(Nio2CompletionHandler.java:38)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at org.apache.sshd.common.io.nio2.Nio2CompletionHandler.completed(Nio2CompletionHandler.java:37)
	at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127)
	at java.base/sun.nio.ch.Invoker$2.run(Invoker.java:219)
	at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

This NPE is expected, because pipe is indeed null here:

https://github.com/apache/mina-sshd/blob/master/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java#L119

Becuase it's set only when streaming is sync:

https://github.com/apache/mina-sshd/blob/master/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java#L109

Shouldn't doWriteData be called at all or it has incorrect implementation in the case of async streaming?

Expected behavior

I expect that reading from asyncOut works without exceptions.

Relevant log output

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

bugAn issue describing a bug in the code

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions