我正在使用异步邮件客户端,因此需要解决MX dns记录。我为此使用Netty 4.1.36 Final
。大多数情况下,我的程序运行良好,但有时会抛出以下异常:
io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(512) + length(2) exceeds writerIndex(512): PooledUnsafeDirectByteBuf(ridx: 512, widx: 512, cap: 4096)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) ~[netty-codec-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1408) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:930) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:682) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:617) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:534) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496) ~[netty-transport-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.36.Final.jar:4.1.36.Final]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: java.lang.IndexOutOfBoundsException: readerIndex(512) + length(2) exceeds writerIndex(512): PooledUnsafeDirectByteBuf(ridx: 512, widx: 512, cap: 4096)
at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1428) ~[netty-buffer-4.1.36.Final.jar:4.1.36.Final]
at io.netty.buffer.AbstractByteBuf.readShort(AbstractByteBuf.java:742) ~[netty-buffer-4.1.36.Final.jar:4.1.36.Final]
at io.netty.buffer.AbstractByteBuf.readUnsignedShort(AbstractByteBuf.java:758) ~[netty-buffer-4.1.36.Final.jar:4.1.36.Final]
at io.netty.handler.codec.dns.DefaultDnsRecordDecoder.decodeRecord(DefaultDnsRecordDecoder.java:61) ~[netty-all-4.1.36.Final.jar:4.1.36.Final]
at io.netty.handler.codec.dns.DatagramDnsResponseDecoder.decodeRecords(DatagramDnsResponseDecoder.java:110) ~[netty-all-4.1.36.Final.jar:4.1.36.Final]
at io.netty.handler.codec.dns.DatagramDnsResponseDecoder.decode(DatagramDnsResponseDecoder.java:68) ~[netty-all-4.1.36.Final.jar:4.1.36.Final]
at io.netty.handler.codec.dns.DatagramDnsResponseDecoder.decode(DatagramDnsResponseDecoder.java:33) ~[netty-all-4.1.36.Final.jar:4.1.36.Final]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[netty-codec-4.1.36.Final.jar:4.1.36.Final]
... 16 common frames omitted
查看它,我怀疑它可能与DNS服务器的截断响应有关,但是我无法确认错误是在我的代码收到响应之前引发的。
答案 0 :(得分:0)
似乎Decoder
无法将其写入ByteBuf
,因为您的消息有很多字节。你我把它分开。