Skip to content

Eclipse Paho MQTT v5 Client subscribe() Method Infinite Recursion Causes StackOverflowError #1100

@sushijia123

Description

@sushijia123

Content Description:

Problem Description

When using the Eclipse Paho MQTT v5 client library (version 1.2.5), calling the MqttClient.subscribe() method results in a java.lang.StackOverflowError exception. The error stack trace shows that the method repeatedly calls itself at line 525 in the org.eclipse.paho.mqttv5.client.MqttClient class, forming an infinite recursion.

Error Stack Trace

java.lang.StackOverflowError at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) at org.eclipse.paho.mqttv5.client.MqttClient.subscribe(MqttClient.java:525) ... (hundreds of repeated calls to the same method)

Code Analysis

An obvious infinite recursion issue was found in the MqttClient class:

public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException {
return this.subscribe(topicFilters, qos, messageListeners); // Calls itself, causing infinite recursion
}

Environment Information

  • MQTT Client Library: Eclipse Paho MQTT v5
  • Version: 1.2.5
  • Dependency Configuration:
org.eclipse.paho org.eclipse.paho.mqttv5.client 1.2.5 compile true

Reproduction Steps

  1. Create an MqttClient instance and establish a connection
  2. Call the subscribe method to subscribe to any topic
  3. Observe the StackOverflowError exception

Expected Behavior

The subscribe method should execute the subscription operation normally without falling into infinite recursion and causing a stack overflow.

Additional Information

  • The issue occurs in both the MQTT client initialization and reconnection logic
  • No subscription calls are made within the messageArrived method, ruling out recursion caused by custom code
  • The project also depends on MQTT v3 client library (same version), but the issue appears in v5 client calls

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions