eclipse-paho / eclipse-paho/paho.mqtt.java
External executor service broken in v1.2.1
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 919
- PR merge metrics
- No merged PRs in 30d
Description
- [X] Bug exists Release Version 1.2.1 ( Master Branch)
- [?] Bug exists in MQTTv3 Client on Snapshot Version 1.2.1-SNAPSHOT (Develop Branch)
- [?] Bug exists in MQTTv5 Client on Snapshot Version 1.2.1-SNAPSHOT (Develop Branch)
`new MqttAsyncClient("broker", "clientId", new MemoryPersistence(), new TimerPingSender(), Executors.newScheduledThreadPool(numThreads, threadFactory))` causes the following behaviors:
1. The JVM hangs on exit if the executor service uses non-daemon threads, even after invoking `shutdown()`/`shutdownNow()` on the executor service. This seems to be related to/a regression of https://github.com/eclipse/paho.mqtt.java/issues/402, and I did experience this behavior in v1.2.0. Using a custom thread factory that produces daemon threads, per https://github.com/eclipse/paho.mqtt.java/issues/402#issuecomment-424686340, is a suitable workaround.
1. The following exceptions occur when using any executor service. Not using an executor service at all, and thus relying on explicitly created threads, fixes all of these exceptions. _None of these exceptions occur in v1.2.0._
Executor with more than 1 thread (daemon and non-daemon threads):
```
# During connect
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:189)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
... 6 more
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:267)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:92)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:136)
... 7 more
```
Executor with more than 1 thread (non-daemon threads only):
```
# During publish; occurs after the above error happens during connect
java.lang.NullPointerException
at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:197)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:1251)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:1224)
```
Executor with 1 thread (daemon and non-daemon threads):
```
# During connect
Timed out waiting for a response from the server (32000)
at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(Token.java:112)
at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(MqttToken.java:67)
# During disconnect
Connect already in progress (32110)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.close(ClientComms.java:235)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.close(MqttAsyncClient.java:1491)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.close(MqttAsyncClient.java:1479)
```
Contributor guide
Assessment
This issue has not been assessed yet.