eclipse-paho / eclipse-paho/paho.mqtt.java
Connection lost (32109) - EOFException after connect for Websocket connection
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 919
- PR merge metrics
- No merged PRs in 30d
Description
Please fill out the form below before submitting, thank you!
- [x] Bug exists Release Version 1.2.5 ( Master Branch)
- [ ] Bug exists in MQTTv3 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
- [ ] Bug exists in MQTTv5 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
I still see this issue from version 1.11, 1.2.0, and now 1.2.5. It never seems to have been fixed correctly.
2021-07-07 07:52:28.879 11703-11703/com.example.paho_125_test I/MQTTService: startKeepAlives()->start
2021-07-07 07:52:28.886 11703-11703/com.example.paho_125_test I/MQTTService: startKeepAlives()->rescheduled keepalive
2021-07-07 07:52:28.886 11703-11703/com.example.paho_125_test I/MQTTService: startKeepAlives()->KEEP_ALIVE UUID sent=0b134bc5-71d4-40ee-bb7e-e6c30bc43966
2021-07-07 07:52:28.886 11703-11703/com.example.paho_125_test I/MQTTService: startKeepAlives()->KEEP_ALIVE Interval sent=10000
2021-07-07 07:52:28.886 11703-11703/com.example.paho_125_test I/MQTTService: startKeepAlives()->end
2021-07-07 07:55:55.142 11703-25488/com.example.paho_125_test E/MQTTService: connectionLost()->start
2021-07-07 07:55:55.160 11703-25488/com.example.paho_125_test E/MQTTService: connectionLost()->Cause=
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:197)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:270)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:92)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:137)
at java.lang.Thread.run(Thread.java:919)
2021-07-07 07:55:55.162 11703-25488/com.example.paho_125_test E/MQTTService: connectionLost()->end
See https://github.com/eclipse/paho.mqtt.java/issues/673 and https://github.com/eclipse/paho.mqtt.java/issues/679
Wired connections work fine, but it seems the variability of wifi on Android may be the underlying cause. Just my theory.
My attempts to apply the fix in https://github.com/eclipse/paho.mqtt.java/issues/673 cause high CPU usage on Android.
Changing lines 137 in CommsReceiver as follows
MqttWireMessage message = null;
synchronized (lifecycle) {
**if (in.available>0){**
message = in.readMqttWireMessage();
}
current_state = State.RUNNING;
}
Would appear to fix the issue, but the affect on the while{} loop seems to trigger constant high CPU in the Android studio profiler.
Not sure if this change in MqttInputStream would have a similar high CPU affect.
public MqttWireMessage readMqttWireMessage() throws IOException, MqttException {
final String methodName ="readMqttWireMessage";
MqttWireMessage message = null;
**if (!(in.available() > 0)){
return message;
}**
try {
// read header
if (remLen < 0) {
Testing a fix for this issue requires leaving Android code running for 24hrs as it specifically seems to occur overnight during low device usage.
BTW - The default socket timeout of 1s may be too small for Android on Wifi. I'm currently testing 1600ms to see if it fixes the issue. Other have bumped there socket timeout value to 5s.
https://stackoverflow.com/questions/30378288/android-socket-connection-timeout
Contributor guide
Research direction
Start with the stack-trace paths in CommsReceiver.java and MqttInputStream.java, then compare the related reports in issues 673 and 679. Reproduce the connection over Android Wi-Fi during an extended low-use period and measure the effect of any change on EOF disconnects and CPU usage; done means the failure and regression behavior are characterized and covered by an agreed fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100