paho.mqtt.java
paho.mqtt.java copied to clipboard
Connection lost (32109) - java.io.EOFException
Connection lost (32109) - java.io.EOFException at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:181) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) 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:133) ... 7 more
Code snippet used to build mqtt client:
__public static MqttClient addClientWithLogin(String address, String id, String uid, String pwd, ArrayList topics, MqttCallback mqttCallback) { MqttClient client = null; try { client = new MqttClient(address, id); MqttConnectOptions opts = new MqttConnectOptions(); opts.setUserName(uid); opts.setPassword(pwd.toCharArray()); opts.setCleanSession(true); opts.setMaxInflight(1000); opts.setKeepAliveInterval(15); opts.setConnectionTimeout(0); client.setCallback(mqttCallback); client.connect(opts); if (topics != null && topics instanceof ArrayList) { Object[] listOfTopics = topics.toArray(); for (Object topic : listOfTopics) { client.subscribe(topic.toString()); } } } catch (MqttException ex) { logger.error(ExceptionUtils.getStackTrace(ex)); }
return client;
}__
Can you add a null check for the Subscription topics in the list and see if you encounter any list element with null value. I can see that your code snippet is doing the null check for the Arraylist, but not for individual topics before passing it on to API.
I remember facing a similar issue in subscription when null is passed on to client.subscribe().
@Vi-Nk ,
Before passing ArrayList we are making a null check on each topic. Could please advise how to proceed with this?
@Kalyan-D I am providing inputs purely on my experience as the consumer of this library. Few points I can provide to work with, listed based on the significance they have on the connection with the broker:
-
are you running the same code on multiple machines? If so, are you making sure that the client ID you are providing for the connection option is unique each time / for each machine? This is the major cause of EOF exceptions and connection terminations.
-
Can you set the connection timeout to ~30 seconds, considering the network latency? For my applications, Keepalive timer of 15-20 seconds goes with a connection timeout of 30 seconds.
Do experiment and let me know of the observation/progress.
@Vi-Nk Thanks for the information! It helped me to fix this issue, my mistake was that i passed an empty list of topics to the client, so adding the checking for empty list fixed it.