eclipse-paho / eclipse-paho/paho.mqtt.java
Catch client is disconnected using the V3.1 protocol.
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 919
- PR merge metrics
- No merged PRs in 30d
Description
migrated from Bugzilla [#460139](https://bugs.eclipse.org/bugs/show_bug.cgi?id=460139)
status UNCONFIRMED severity _normal_ in component _MQTT-Java_ for _1.1_
Reported in version _1.1_ on platform _PC_
Assigned to: Bin Zhang
Original attachment names and IDs:
- _[mqxr_0.trc](https://bugs.eclipse.org/bugs//attachment.cgi?id=251684)_ (ID 251684)
On 2015-02-17 11:24:39 -0500, Andrew Banks wrote:
> I connect a client to a server that only supports the V3.1 protocol, so in reality it has to first connect using the 3.1.1 protocol and then the 3.1 protocol.
>
> I wait for the connection to complete using
>
> IMqttAsyncClient.pubClient.connect(options).waitForCompletion();
>
> then sometimes when I disconnect the client I catch :
>
> org.eclipse.paho.client.mqttv3.MqttException: Client is disconnected
> Client is disconnected (32101)
> at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
> at org.eclipse.paho.client.mqttv3.internal.ClientComms.disconnect(ClientComms.java:422)
> at org.eclipse.paho.client.mqttv3.MqttAsyncClient.disconnect(MqttAsyncClient.java:537)
> at org.eclipse.paho.client.mqttv3.MqttAsyncClient.disconnect(MqttAsyncClient.java:506)
> at com.ibm.mqttv3.test.Mqtt31SRNB_Variation.disconnectClients(Mqtt31SRNB_Variation.java:966)
> at com.ibm.mqttv3.test.Mqtt31SRNB_Variation.testBatchedThrNBRC(Mqtt31SRNB_Variation.java:338)
On 2015-03-10 04:26:36 -0400, Bin Zhang wrote:
> Any test case or a simple program to produce ?
On 2015-03-18 05:13:10 -0400, Andrew Banks wrote:
> Bin, I cant make an easily reproducible test case but calling the following method repeatedly several hundred time for the same client connected to a server that upports the MQTTV3.1 protocol but not the MQTTV3.1.1 protocol, will eventually recreate the problem.
>
> private void doPublish(final IMqttAsyncClient pubClient,
> final String topicName, Executor executor, final byte[] payload,
> final int qos, final boolean retained, final boolean tryBadTopic,
> final boolean tryBadQos, final CountDownLatch pubPubLatch,
> final boolean reconnectAfter, final boolean reconnectBefore,
> final int secondaryId) {
> final String clientId = pubClient.getClientId() + secondaryId;
> log.fine(clientId + " 0 publishing {" + new String(payload)
> + "} on {" + topicName + "}");
> executor.execute(new Runnable() {
>
> ```
> public void run() {
>
> synchronized (pubClient) { // Don't reconnect while someone else
> Thread.currentThread().setName(clientId);
> // is publishing
> if (reconnectBefore) {
> try {
> log.fine(clientId
> + " 10 disconnecting before publishing, secondaryId="+secondaryId);
> pubClient.disconnect().waitForCompletion();
> log.fine(clientId
> + " 10 reconnecting before publishing, secondaryId="+secondaryId);
> pubClient.connect(options).waitForCompletion();
> }
> catch (MqttException e) {
> failed = true;
> for (int i=0; i log.fine(clientId + " Exception:"+e+" "+e.getStackTrace()[i]);
> Assert.fail("publisher reconnect FAILED " + e);
> }
> }
>
> if (tryBadTopic) {
> log.fine(clientId
> + " 12 dummy publish with a bad topic");
> try {
> pubClient.publish("#/+", payload, qos, retained,
> null, null);
> failed = true;
> Assert.fail("publish to bad topic succeeded");
> }
> catch (IllegalArgumentException e) {
> log.fine(clientId
> + " 14 dummy publish with a bad topic FAILED as expected");
> }
> catch (MqttException e) {
> failed = true;
> Assert.fail("publish to bad topic FAILED with an unexpected exception "
> + e);
> }
> }
> if (tryBadQos) {
> log.fine(clientId
> + " 16 dummy publish with a bad qos value");
> try {
> pubClient.publish(topicName, payload, -1, retained,
> null, null);
> failed = true;
> Assert.fail("publish with bad qos succeeded");
> }
> catch (IllegalArgumentException e) {
> log.fine(clientId
> + " 18 dummy publish with a bad qos value FAILED as expected");
> }
> catch (MqttException e) {
> failed = true;
> Assert.fail("publish with a bad qos value FAILED with an unexpected exception "
> + e);
> }
> }
>
> try {
> log.fine(clientId
> + " 88 About to publish, secondaryId="+secondaryId);
> IMqttToken publishToken = pubClient.publish(topicName,
> payload, qos, retained, null,
> new IMqttActionListener() {
>
> public void onSuccess(
> IMqttToken asyncActionToken) {
> pubPubLatch.countDown();
> log.fine(clientId
> + " 20 success latch count after countDown() : "
> + pubPubLatch.getCount());
> }
>
> public void onFailure(
> IMqttToken asyncActionToken,
> Throwable exception) {
> log.fine(clientId
> + " 20 FAILURE "
> + exception);
> if ((exception instanceof MqttException)
> && (((MqttException) exception)
> .getReasonCode() == MqttException.REASON_CODE_CLIENT_DISCONNECTING)) {
> // this is probably due to another
> // thread doing the
> // disconnect/reconnect cycle on
> // this client
> // we would expect the publish to
> // subsequently succeed.
> log.fine(clientId + " 25 this failure is expected");
> }
> else {
> pubPubLatch.countDown();
> Assert.fail("publish FAILED");
> }
> }
> });
> if (reconnectAfter) {
> publishToken.waitForCompletion();
> log.fine(clientId
> + " 30 disconnecting and reconnecting after publishing");
> try {
> pubClient.disconnect().waitForCompletion();
> log.fine(clientId
> + " 40 disconnected - reconnecting after publishing");
> pubClient.connect(options).waitForCompletion();
> }
> catch (MqttException e) {
> failed = true;
> for (int i=0; i log.fine("Exception:"+e+" "+e.getStackTrace()[i]);
> Assert.fail("publisher reconnect FAILED " + e);
> }
> }
> log.fine(clientId + " 555 run() complete");
> }
> catch (MqttException e) {
> failed = true;
> log.fine("Exception:"+e+" "+e.getStackTrace());
> Assert.fail("publish FAILED " + e);
> }
>
> }
> }
>
> });
> log.fine(clientId + " 50 publish complete");
> ```
>
> }
On 2015-03-18 05:33:13 -0400, Andrew Banks wrote:
> Created attachment 251684
> Trace file to match exception.
Contributor guide
Assessment
This issue has not been assessed yet.