Fixed memory leaks in MqttTransportHandler (#1787)
This commit is contained in:
parent
e31052bc39
commit
4255bf485a
@ -34,6 +34,7 @@ import io.netty.handler.codec.mqtt.MqttSubscribeMessage;
|
|||||||
import io.netty.handler.codec.mqtt.MqttTopicSubscription;
|
import io.netty.handler.codec.mqtt.MqttTopicSubscription;
|
||||||
import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage;
|
import io.netty.handler.codec.mqtt.MqttUnsubscribeMessage;
|
||||||
import io.netty.handler.ssl.SslHandler;
|
import io.netty.handler.ssl.SslHandler;
|
||||||
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.GenericFutureListener;
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -112,10 +113,14 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||||
log.trace("[{}] Processing msg: {}", sessionId, msg);
|
log.trace("[{}] Processing msg: {}", sessionId, msg);
|
||||||
if (msg instanceof MqttMessage) {
|
try {
|
||||||
processMqttMsg(ctx, (MqttMessage) msg);
|
if (msg instanceof MqttMessage) {
|
||||||
} else {
|
processMqttMsg(ctx, (MqttMessage) msg);
|
||||||
ctx.close();
|
} else {
|
||||||
|
ctx.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
ReferenceCountUtil.safeRelease(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,6 +426,11 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader);
|
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||||
|
ctx.flush();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||||
log.error("[{}] Unexpected Exception", sessionId, cause);
|
log.error("[{}] Unexpected Exception", sessionId, cause);
|
||||||
|
|||||||
@ -212,18 +212,14 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String validatePayload(UUID sessionId, ByteBuf payloadData, boolean isEmptyPayloadAllowed) throws AdaptorException {
|
private static String validatePayload(UUID sessionId, ByteBuf payloadData, boolean isEmptyPayloadAllowed) throws AdaptorException {
|
||||||
try {
|
String payload = payloadData.toString(UTF8);
|
||||||
String payload = payloadData.toString(UTF8);
|
if (payload == null) {
|
||||||
if (payload == null) {
|
log.warn("[{}] Payload is empty!", sessionId);
|
||||||
log.warn("[{}] Payload is empty!", sessionId);
|
if (!isEmptyPayloadAllowed) {
|
||||||
if (!isEmptyPayloadAllowed) {
|
throw new AdaptorException(new IllegalArgumentException("Payload is empty!"));
|
||||||
throw new AdaptorException(new IllegalArgumentException("Payload is empty!"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return payload;
|
|
||||||
} finally {
|
|
||||||
payloadData.release();
|
|
||||||
}
|
}
|
||||||
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user