Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection to HiveMQ dropping with an error #1623

Open
nicholasmparker opened this issue Mar 1, 2024 · 12 comments
Open

Connection to HiveMQ dropping with an error #1623

nicholasmparker opened this issue Mar 1, 2024 · 12 comments
Labels
needs-more-info A little more info requested from the submitter

Comments

@nicholasmparker
Copy link

Anyone experiencing this? From the debug logs
2024-03-01 10:47:36.005 E MessageProcessorEndpointMqtt: connectionLost error
(32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(Unknown Source:213)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:275)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(SourceFile:14)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(Unknown Source:64)
... 1 more

@jpmens
Copy link
Member

jpmens commented Mar 1, 2024

Under the assumption that this error is on our Android app, I'll transfer this issue.

@jpmens jpmens transferred this issue from owntracks/talk Mar 1, 2024
@growse
Copy link
Collaborator

growse commented Mar 1, 2024

Difficult to know what's going on here. Could be the network, could be the broker not being responsive, could be the device not waking the app to do keepalives....

@growse growse added the needs-more-info A little more info requested from the submitter label Mar 1, 2024
@da-mkay
Copy link

da-mkay commented Mar 19, 2024

Hi,

I have exactly the same issue:

2024-03-18 22:11:13.042 E MessageProcessorEndpointMqtt: connectionLost error
2024-03-18 22:11:13.042 E MessageProcessorEndpointMqtt: (32109) - java.io.EOFException
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(Unknown Source:213)
    at java.lang.Thread.run(Thread.java:1012)
2024-03-18 22:11:13.042 E MessageProcessorEndpointMqtt: Caused by: java.io.EOFException
    at java.io.DataInputStream.readByte(DataInputStream.java:275)
    at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(SourceFile:14)
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(Unknown Source:64)
2024-03-18 22:11:13.042 E MessageProcessorEndpointMqtt: ... 1 more

The Android phone (Samsung Galaxy S21 FE) connects to the broker, keeps the connection for "exactly" 1 minute, then disconnects. Then I see the error above.
But then it immediately reconnects. Thus, in my broker logs I see an LWT message and reconnect every minute:

[2024-03-18 22:10:12.523] moe connected
[2024-03-18 22:10:12.540] moe subscribed topics: owntracks/+/+ owntracks/+/+/event owntracks/+/+/info owntracks/+/+/waypoints owntracks/moe/phone/cmd
[2024-03-18 22:11:12.585] moe published to owntracks/moe/phone :
[2024-03-18 22:11:12.585] {"_type":"lwt","tst":1710796212}
[2024-03-18 22:11:12.585] moe disconnected

[2024-03-18 22:11:13.454] moe connected
[2024-03-18 22:11:13.470] moe subscribed topics: owntracks/+/+ owntracks/+/+/event owntracks/+/+/info owntracks/+/+/waypoints owntracks/moe/phone/cmd
[2024-03-18 22:12:13.516] moe published to owntracks/moe/phone :
[2024-03-18 22:12:13.516] {"_type":"lwt","tst":1710796273}
[2024-03-18 22:12:13.516] moe disconnected

[2024-03-18 22:12:14.231] moe connected
[2024-03-18 22:12:14.242] moe subscribed topics: owntracks/+/+ owntracks/+/+/event owntracks/+/+/info owntracks/+/+/waypoints owntracks/moe/phone/cmd
[2024-03-18 22:13:14.255] moe published to owntracks/moe/phone :
[2024-03-18 22:13:14.255] {"_type":"lwt","tst":1710796334}
[2024-03-18 22:13:14.255] moe disconnected

It doesn't matter if the phone uses WiFi or mobile network. Since it happens almost exactly each minute and the immediate reconnect works, it doesn't look to me like some network or server issue.

My iPhone stays connected all the time if I leave the app open. Running in the background it connects on demand (pushing location) and closes the connection afterwards.

Btw, I use MQTT over websockets. The MQTT broker sits behind an nginx reverse proxy.
Connection between app and nginx is encrypted and secured via client certificate.
The same is true for the connection between nginx and the broker.

@ckrey
Copy link
Member

ckrey commented Mar 19, 2024

Probably nginx terminates the connection after 60 seconds of inactivity (https://nginx.org/en/docs/http/websocket.html)
Either increase timeout values or investigate if nginx can do keepalive

@da-mkay
Copy link

da-mkay commented Mar 19, 2024

Yep, it looks like increasing the timeouts in nginx solved it for me 😉

@jpmens
Copy link
Member

jpmens commented Mar 19, 2024

@nicholasmparker can you confirm this solves the issue for you likewise?

@da-mkay
Copy link

da-mkay commented Mar 23, 2024

After increasing the timeouts to 1 day in nginx I monitored the reconnects a few days. Sometimes the phone kept the connection for 2h, sometimes for 1h or 30 min or 22 min. The reconnect usually happened within 0 to 10 minutes. And when the connection is lost I see the error from the first post. Maybe these are "normal" connection losses due to ... Android stuff 😉

But today I switched the MQTT broker to Mosquitto, without changing the nginx config. Now I see the error log every exact 5 minutes while keep alive is set to 900s in the app. Reconnect happens immediately according to mosquitto logs. I do not see this behavior when opening the iOS app for let's say 10 minutes. It stays connected all the time.

Any ideas where this new magic 5 minutes come from? This was not the case with the last broker I used (aedes based).

@growse
Copy link
Collaborator

growse commented Mar 25, 2024

You've not said what device you're using, and that 5 mins could be a device thing. Do you see anything in the OT log about why it dropped the connection?

@da-mkay
Copy link

da-mkay commented Apr 7, 2024

It is a Galaxy S21 FE. The OT log shows the error from the first posts here (connectionLost error).

A few days ago I switched back from Mosquitto to my other broker, and the connection losses every exact 5 minutes are gone. Now I am back to the behavior where the Android app can sometimes keep the connection for 2 hours, sometimes for 20 minutes and so on, which I guess is normal.

I don't know what the problem is between Android app and Mosquitto, because my other broker works well.
I also noticed some problems between iOS app and Mosquitto that I do not have with the other broker: When I opened the app I always saw an old outdated location of a friend. I always had to restart the app to see the current location.

I can solve both problems by replacing Mosquitto (v2.0.18 btw) which is fine for me.
But it would still be good to know what's the problem with Mosquitto. Are there any known issues or incompatibilities with Owntracks and Mosquitto?

@jpmens
Copy link
Member

jpmens commented Apr 8, 2024

I'm having a hard time following. What is "my other broker", is that HiveMQ?

We're not aware of issues with Android and Mosquitto over MQTT, in fact most of us have that combination.

Can you get rid of the websocket connection and use plain MQTT (port 1883, or 8883 with TLS)?

@ckrey
Copy link
Member

ckrey commented Apr 8, 2024

When switching between differen MQTT backends make sure to empty queues on the broker end by either

  • resetting broker (mosquitto: delete mosquitto persistence db)
  • connect once with CleanSession flag set (modify settings in OwnTracks App or use another MQTT client using the same clientId)

@da-mkay
Copy link

da-mkay commented Apr 9, 2024

I'm having a hard time following. What is "my other broker", is that HiveMQ?

It's my own broker based on aedes (will be released soon).

We're not aware of issues with Android and Mosquitto over MQTT, in fact most of us have that combination.
Can you get rid of the websocket connection and use plain MQTT (port 1883, or 8883 with TLS)?

That's interesting. Unfortunately I don't have permanent access to the Android phone, so testing that scenario is a bit difficult. Maybe I can find an old Android phone here and reproduce the issue.

When switching between differen MQTT backends make sure to empty queues on the broker end by either

  • resetting broker (mosquitto: delete mosquitto persistence db)
  • connect once with CleanSession flag set (modify settings in OwnTracks App or use another MQTT client using the same clientId)

I did the latter by setting the clean flag in the app and restarting the app, then switched back to clean=false and restarted the app again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-info A little more info requested from the submitter
Projects
None yet
Development

No branches or pull requests

5 participants