Merge pull request #7519 from smatvienko-tb/mqtt-transport-log-shorter-on-io-exception

[3.4.2] MQTT transport: Make log shorter on IOException
This commit is contained in:
Andrew Shvayka 2022-11-02 14:08:26 +02:00 committed by GitHub
commit 13996b6ce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -883,7 +883,22 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
log.error("[{}] Unexpected Exception", sessionId, cause);
if (cause instanceof IOException) {
if (log.isDebugEnabled()) {
log.debug("[{}][{}][{}] IOException: {}", sessionId,
Optional.ofNullable(this.deviceSessionCtx.getDeviceInfo()).map(TransportDeviceInfo::getDeviceId).orElse(null),
Optional.ofNullable(this.deviceSessionCtx.getDeviceInfo()).map(TransportDeviceInfo::getDeviceName).orElse(""),
cause);
} else if (log.isInfoEnabled()) {
log.info("[{}][{}][{}] IOException: {}", sessionId,
Optional.ofNullable(this.deviceSessionCtx.getDeviceInfo()).map(TransportDeviceInfo::getDeviceId).orElse(null),
Optional.ofNullable(this.deviceSessionCtx.getDeviceInfo()).map(TransportDeviceInfo::getDeviceName).orElse(""),
cause.getMessage());
}
} else {
log.error("[{}] Unexpected Exception", sessionId, cause);
}
ctx.close();
if (cause instanceof OutOfMemoryError) {
log.error("Received critical error. Going to shutdown the service.");