Browse Source

fix: release DirectByteBuffer after MQTT SSL auth to prevent native memory leak

Holding sslHandler as a final field kept SSLEngine and its JNI-allocated
DirectByteBuffers alive for the full session lifetime. On rapid reconnect
loops this caused linear native memory growth, eventually hitting OOM.

Null the reference at the end of onValidateDeviceResponse() so SslHandler
becomes eligible for Young GC immediately after authentication completes.
Add boolean ssl flag to preserve isSSL semantics after the field is cleared.
pull/15743/head
pon0marev 2 months ago
parent
commit
4a85b2fee8
  1. 5
      common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java

5
common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java

@ -150,7 +150,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
protected final MqttTransportContext context;
private final TransportService transportService;
private final SchedulerComponent scheduler;
private final SslHandler sslHandler;
private final boolean ssl;
private volatile SslHandler sslHandler;
private final ConcurrentMap<MqttTopicMatcher, Integer> mqttQoSMap;
final DeviceSessionCtx deviceSessionCtx;
@ -172,6 +173,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
this.context = context;
this.transportService = context.getTransportService();
this.scheduler = context.getScheduler();
this.ssl = sslHandler != null;
this.sslHandler = sslHandler;
this.mqttQoSMap = new ConcurrentHashMap<>();
this.deviceSessionCtx = new DeviceSessionCtx(sessionId, mqttQoSMap, context);
@ -1373,6 +1375,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
}
});
}
this.sslHandler = null;
}
@Override

Loading…
Cancel
Save