diff --git a/broker/src/main/java/io/moquette/server/netty/NettyMQTTHandler.java b/broker/src/main/java/io/moquette/server/netty/NettyMQTTHandler.java index 1f5ca354..0e4a9854 100644 --- a/broker/src/main/java/io/moquette/server/netty/NettyMQTTHandler.java +++ b/broker/src/main/java/io/moquette/server/netty/NettyMQTTHandler.java @@ -23,12 +23,10 @@ import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.handler.codec.CorruptedFrameException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; /** * @@ -47,7 +45,10 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object message) { AbstractMessage msg = (AbstractMessage) message; - LOG.info("Received a message of type {}", Utils.msgType2String(msg.getMessageType())); + String messageType = Utils.msgType2String(msg.getMessageType()); + if (LOG.isDebugEnabled()) { + LOG.debug("Processing MQTT message. MessageType = {}.", messageType); + } try { switch (msg.getMessageType()) { case CONNECT: @@ -82,9 +83,11 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter { ctx.writeAndFlush(pingResp); break; } - } catch (Exception ex) { - LOG.error("Bad error in processing the message", ex); - ctx.fireExceptionCaught(ex); + } catch (Throwable ex) { + LOG.error( + "An unexpected exception was caught while processing MQTT message. MessageType = {}, cause = {}, errorMessage = {}.", + messageType, ex.getCause(), ex.getMessage()); + ctx.fireExceptionCaught(ex); } } @@ -92,6 +95,7 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter { public void channelInactive(ChannelHandlerContext ctx) throws Exception { String clientID = NettyUtils.clientID(ctx.channel()); if (clientID != null && !clientID.isEmpty()) { + LOG.info("Notifying connection lost event. MqttClientId = {}.", clientID); m_processor.processConnectionLost(clientID, ctx.channel()); } ctx.close(); @@ -99,14 +103,9 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - if (cause instanceof CorruptedFrameException) { - //something goes bad with decoding - LOG.warn("Error decoding a packet, probably a bad formatted packet, message: " + cause.getMessage()); - } else if (cause instanceof IOException && "Connection reset by peer".equals(cause.getMessage())) { - LOG.warn("Network connection closed abruptly"); - } else { - LOG.error("Ugly error on networking", cause); - } + LOG.error( + "An unexpected exception was caught while processing MQTT message. Closing Netty channel. MqttClientId = {}, cause = {}, errorMessage = {}.", + NettyUtils.clientID(ctx.channel()), cause.getCause(), cause.getMessage()); ctx.close(); }