hivemq/hivemq-mqtt-client

BlockingClient receive(long, Duration) Memory leak

imascha opened this issue ยท 1 comments

๐Ÿ› Bug Report

The member Variable List: entries inside: com.hivemq.client.internal.mqtt.MqttBlockingClient.MqttPublishes increases in size with each call to receive(long, Duration)
The entries list seems to only get cleared, when a message to a subscribed topic is received. This can cause memory problems, when no message is received for a long time.

๐Ÿ”ฌ How To Reproduce

Steps to reproduce the behavior:

  1. Subscribe to a Topic that does not receive any messages
  2. Call receive(long, Duration) in a loop with a small duration. (Im using a larger duration in my application, but choose a small one here to reproduce the problem quicker)

Code sample

  var blockingClient = Mqtt5Client.builder()
          .identifier("blocking-subscriber")
          .serverHost("localhost")
          .serverPort(1883)
          .automaticReconnectWithDefaultConfig()
          .buildBlocking();

  try (final Mqtt5BlockingClient.Mqtt5Publishes publishes = blockingClient.publishes(MqttGlobalPublishFilter.ALL)) {
      blockingClient.connect();
      blockingClient.subscribeWith().topicFilter("example/topic").send();

      while (true) {
          var publish = publishes.receive(1, TimeUnit.MICROSECONDS);
      }
  }

Environment

What version of this client are you using?

1.3.3

JVM version?

21

Operating System?

Windows 10

Which MQTT protocol version is being used?

5

Which MQTT broker (name and version)?

mosquitto 2.0.15

Screenshots

Memory
image

๐Ÿ“ˆ Expected behavior

The entries list should probably be periodically cleared, even when no messages are received.

Hi @imascha

Thank you for your report and that you already found out the cause for this behavior.
I will take a look, but can not promise a deadline.