From 7928a6fef3a0d72c17f8f4b2a5123cc433365de8 Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Mon, 12 Feb 2018 09:31:36 -0800 Subject: [PATCH] NioDatagramChannel invalid usage of internalNioBuffer Motivation: NioDatagramChannel attempts to unpack a AddressedEnvelope and unconditionally uses internalNioBuffer. However if the ByteBuf is a CompositeByteBuf with more than 1 components, the write will fail and throw an exception. Modifications: - NioDatagramChannel should check the nioBufferCount before attempting to use internalNioBuffer Result: No more failure to write UDP packets on NIO when a CompositeByteBuf is used. --- .../java/io/netty/channel/socket/nio/NioDatagramChannel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java index 9803bfa2a0..2fc314d752 100644 --- a/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java +++ b/transport/src/main/java/io/netty/channel/socket/nio/NioDatagramChannel.java @@ -286,7 +286,8 @@ public final class NioDatagramChannel return true; } - final ByteBuffer nioData = data.internalNioBuffer(data.readerIndex(), dataLen); + final ByteBuffer nioData = data.nioBufferCount() == 1 ? data.internalNioBuffer(data.readerIndex(), dataLen) + : data.nioBuffer(data.readerIndex(), dataLen); final int writtenBytes; if (remoteAddress != null) { writtenBytes = javaChannel().send(nioData, remoteAddress);