Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.handler.codec.EncoderException;
import io.netty.util.ReferenceCountUtil;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_ENCODE_IN_IO_THREAD;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
Expand Down Expand Up @@ -185,10 +186,11 @@ public void send(Object message, boolean sent) throws RemotingException {

boolean success = true;
int timeout = 0;
ByteBuf buf = null;
try {
Object outputMessage = message;
if (!encodeInIOThread) {
ByteBuf buf = channel.alloc().buffer();
buf = channel.alloc().buffer();
ChannelBuffer buffer = new NettyBackedChannelBuffer(buf);
codec.encode(this, buffer, message);
outputMessage = buf;
Expand Down Expand Up @@ -224,6 +226,10 @@ public void operationComplete(ChannelFuture future) throws Exception {
}
} catch (Throwable e) {
removeChannelIfDisconnected(channel);
if (buf != null) {
// Release the ByteBuf if an exception occurs
ReferenceCountUtil.safeRelease(buf);
}
throw new RemotingException(
this,
"Failed to send message " + PayloadDropper.getRequestWithoutData(message) + " to "
Expand Down
Loading