Bug 464318 - Unreported subscribe errors
Summary: Unreported subscribe errors
Status: UNCONFIRMED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Paho (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Bin Zhang CLA
QA Contact: Ian Craggs CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-09 13:50 EDT by Pierre-Luc Lacroix CLA
Modified: 2016-02-05 11:16 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pierre-Luc Lacroix CLA 2015-04-09 13:50:12 EDT
Using paho version 1.0.2 (built on Wed Feb 18 12:11:31 EST 2015)

Take the following example where the broker rejects the subscription "a".

------------------------
Test 1
------------------------
Asking for a subscription to topic "a":
<code>
_mqttClient.subscribe("a");
</code>

Results in the following exception being thrown:
<code>
MqttException
MqttException (128)
	at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:327)
	at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:295)
	at com.lacroix.mqttcore.MQTTClient.subscriptionUpdate(MQTTClient.java:262)
</code>

SUBACK contains 0x80 (Failure) which would warrant the exception.



------------------------
Test 2  (ISSUE/BUG #1)
------------------------

Asking for a subscription to topic "b":
<code>
_mqttClient.subscribe("b");
</code>

In this case, paho will request a QoS of 1 by default. The broker can only provide a QoS of 0 but still allows the subscription.

SUBACK packet contains 0x00 (Success BUT with QoS 0).

Issue: The user is not told that QoS 1 was not successfully granted and that only QoS 0 was provided instead.

I personally don't think this is exception worthy, simply a return code would be sufficient.

------------------------
Test 2  (ISSUE/BUG #2)
------------------------

Asking for a subscription to topic "a" and "b" in the same packet (remember "a" should be rejected by the broker and that "b" will be downgrade to QoS 0):

<code>
String[] requestTopics = { "a", "b" };
int[] requestedQos = { 1, 1 };
_mqttClient.subscribe(requestTopics, requestedQos);
</code>

This is by far the worse scenario, method returns successfully, no exceptions.
If the broker rejects only one of two subscription, paho will not report a failure back.

SUBACK: 0x80 0x00

There are actually two problems in this example:
1) The subscription to "a" failed entirely and the user is never made aware of the issue
2) The subscription to "b" was downgraded to QoS 0 and the user is also not made aware of the issue


-------------------------------------

Hope my explanations were clear enough. To solve these problems we would need the subscribe methods to return useful information (assuming blocking calls) and perhaps a callback would be necessary for non-blocking subscribes (if that is even supported).
Comment 1 Pierre-Luc Lacroix CLA 2015-04-09 15:45:07 EDT
I've just now noticed that the following method:
<code>
public void subscribe(String[] topicFilters, int[] qos) throws MqttException
</code>
overwrites the int array with values received from the broker. The only reason I noticed was because I tried to reuse the array and got unexpected results.

I think that the behaviour is fine but should be documented properly.

Unfortunately I believe we still have a problem with all other subscribe methods (workaround is to use subscribe method taking in two arrays).
Comment 2 James Sutton CLA 2016-02-05 06:14:09 EST
Migrated to GitHub Issue: https://github.com/eclipse/paho.mqtt.java/issues/76