Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing data on closed socket causes unnecessary exception in Netty #15

Open
kornefalk opened this issue Oct 4, 2017 · 0 comments
Open

Comments

@kornefalk
Copy link

public class DefaultSmppSession ...

public void sendResponsePdu(PduResponse pdu) throws RecoverablePduException, UnrecoverablePduException, SmppChannelException, InterruptedException {
...
        // write the pdu out & wait timeout amount of time
        ChannelFuture channelFuture = this.channel.writeAndFlush(buffer);
        if(configuration.getWriteTimeout() > 0){
            channelFuture.await(configuration.getWriteTimeout());
        } else {
            channelFuture.await();
        }

Line 518-523 in master branch at October 4, 2017

By adding a simple test before writing to the socket, the long exception will be avoided
For example add the following code just before:

        if (!this.channel.isOpen()) {
            logger.info("Channel closed.");
            return;
        }

Exception

2017-10-03 12:52:49.809 ERROR 16945 --- [cation.SMPP.csn] c.c.smpp.impl.DefaultSmppSession         : Unable to cleanly return response PDU: {}

com.cloudhopper.smpp.type.SmppChannelException: null
	at com.cloudhopper.smpp.impl.DefaultSmppSession.sendResponsePdu(DefaultSmppSession.java:573) ~[ch-smpp-6.0.0-netty4-beta-3.jar!/:6.0.0-netty4-beta-3]
	at com.cloudhopper.smpp.impl.DefaultSmppSession.firePduReceived(DefaultSmppSession.java:606) ~[ch-smpp-6.0.0-netty4-beta-3.jar!/:6.0.0-netty4-beta-3]
	at com.cloudhopper.smpp.channel.SmppSessionWrapper.channelRead0(SmppSessionWrapper.java:48) [ch-smpp-6.0.0-netty4-beta-3.jar!/:6.0.0-netty4-beta-3]
	at com.cloudhopper.smpp.channel.SmppSessionWrapper.channelRead0(SmppSessionWrapper.java:36) [ch-smpp-6.0.0-netty4-beta-3.jar!/:6.0.0-netty4-beta-3]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at com.cloudhopper.smpp.channel.SmppSessionLogger.channelRead(SmppSessionLogger.java:104) [ch-smpp-6.0.0-netty4-beta-3.jar!/:6.0.0-netty4-beta-3]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at com.cloudhopper.smpp.channel.SmppSessionThreadRenamer.channelRead(SmppSessionThreadRenamer.java:89) [ch-smpp-6.0.0-netty4-beta-3.jar!/:6.0.0-netty4-beta-3]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at com.cloudhopper.smpp.channel.LoggingChannelInboundHandlerAdapter.channelRead(LoggingChannelInboundHandlerAdapter.java:94) [ch-smpp-6.0.0-netty4-beta-3.jar!/:6.0.0-netty4-beta-3]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:642) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:527) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:481) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:441) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) [netty-all-4.1.7.Final.jar!/:4.1.7.Final]
	at java.lang.Thread.run(java.base@9-internal/Thread.java:804) [na:na]
Caused by: java.nio.channels.ClosedChannelException: null
	at io.netty.channel.AbstractChannel$AbstractUnsafe.write(...)(Unknown Source) ~[netty-all-4.1.7.Final.jar!/:4.1.7.Final]
kornefalk added a commit to kornefalk/cloudhopper-smpp that referenced this issue Oct 4, 2017
kornefalk added a commit to kornefalk/cloudhopper-smpp that referenced this issue Oct 4, 2017
kornefalk added a commit to kornefalk/cloudhopper-smpp that referenced this issue Oct 4, 2017
kornefalk added a commit to kornefalk/cloudhopper-smpp that referenced this issue Oct 4, 2017
kornefalk added a commit to kornefalk/cloudhopper-smpp that referenced this issue Oct 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant