在我的代码中的新通道上的第二个 .write ,ChannelFuture.isSuccess
因为写入操作是错误的,并且ChannelFuture.cause
是io.netty.channel.PartialFlushException: 0 out of 1 message(s) flushed
. 我不知道应该做些什么来避免这种情况,以及在哪里寻找更深层次的根本原因。
ChannelFuture.cause.getStackTraceString 是:
io.netty.channel.ChannelOutboundMessageHandlerAdapter.flush(ChannelOutboundMessageHandlerAdapter.java:118) io.netty.channel.CombinedChannelDuplexHandler.flush(CombinedChannelDuplexHandler.java:237) io.netty.channel.DefaultChannelHandlerContext.invokeFlush0(DefaultChannelHandlerContext.java:1308) io. netty.channel.DefaultChannelHandlerContext.write0(DefaultChannelHandlerContext.java:1445) io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:1412) io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:1034) io.netty。 channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:959) io.netty.channel.AbstractChannel.write(AbstractChannel.java:246) pipe.Broker$writer$.write(Broker.scala:72) pipe.Broker$httpClientHandler.messageReceived (Broker.scala:57) 管道。Broker$httpClientHandler.messageReceived(Broker.scala:52) io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:104) io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951) io.netty.channel。 DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926) io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904) io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:466) io.netty.handler。 codec.ByteToMessageDecoder.inboundBufferUpdated(ByteToMessageDecoder.java:69) io.netty.channel.ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelInboundByteHandlerAdapter.java:51) io.netty.channel.CombinedChannelDuplexHandler。inboundBufferUpdated(CombinedChannelDuplexHandler.java:194) io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951) io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926) io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated( DefaultChannelHandlerContext.java:904) io.netty.channel.DefaultChannelPipeline.fireInboundBufferUpdated(DefaultChannelPipeline.java:909) io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:115) io.netty.channel.nio。 NioEventLoop.processSelectedKey(NioEventLoop.java:401) io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:365) io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:302) io.netty。渠道。SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110) java.lang.Thread.run(未知来源)
通道上的第一个 .write 运行良好(isSuccess 为真,并且确实写入的消息完美地到达并在其目的地解析)。但是第二个 .write 始终如所描述的那样失败。
第二个 .write 是从我重写的 ChannelInboundMessageHandlerAdapter 中发出的。messageReceived方法,一旦它接收到远程对等方收到第一个 .write 的确认。
我执行实际写入的代码(这是 Scala)是:
request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"+msg)
var writeFuture = channel.write(request).addListener(new ChannelFutureListener(){
def operationComplete(channelFuture: ChannelFuture){
if (channelFuture.isSuccess)
println("write finished successfully")
else
println ("write failed: " + channelFuture.cause + "\n" + channelFuture.cause.getStackTraceString)
}
})
可能是什么问题,应该如何追踪?