openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.57k forks source link

[xmppclient] permanent connection lost after xmpp server was unreachable/restarted #10482

Open YokaiRick opened 3 years ago

YokaiRick commented 3 years ago

Expected Behavior

If an XMPP Server gets unreachable due to an error or server restart, the binding should connect again after the xmpp server is up again.

Current Behavior

I use a friends xmpp server and it seems it gets rebootet every night. Due to the reboot, the bridge losses its connection and try to connect only one time with a timeout after 5 secs. My only workaround right now is to restart the binding every morning. I know that its not common to restart an xmpp server every night, but this behavoiur should also apear for other people if the connection gets lost for more than 5 secs. In the WebUI the Binding shows itself as online even it is not connected after that connection lost.

Here are some logs during that time:

2021-04-06 06:00:01.801 [WARN ] [oftware.smack.AbstractXMPPConnection] - Connection XMPPTCPConnection[rick_mo@jabber.absturztau.be/XXX] (0) closed with error
org.jivesoftware.smack.XMPPException$StreamErrorException: system-shutdown You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions                                                                                                                                                                                             
<stream:error><system-shutdown xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text>Received SIGTERM</text></stream:error>
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1131) ~[?:?]
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$900(XMPPTCPConnection.java:1063) ~[?:?]
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:1080) ~[?:?]
        at java.lang.Thread.run(Thread.java:834) [?:?]
2021-04-06 06:00:01.825 [DEBUG] [nding.xmppclient.internal.XMPPClient] - Connection to XMPP server was lost.
2021-04-06 06:00:01.827 [DEBUG] [nding.xmppclient.internal.XMPPClient] - XMPP connection was closed.
2021-04-06 06:00:06.925 [INFO ] [nding.xmppclient.internal.XMPPClient] - XMPP connection error
org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). While waiting for establishing TLS
        at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:93) ~[bundleFile:4.3.3]
        at org.jivesoftware.smack.SynchronizationPoint.checkForResponse(SynchronizationPoint.java:317) ~[bundleFile:4.3.3]
        at org.jivesoftware.smack.SynchronizationPoint.checkIfSuccessOrWait(SynchronizationPoint.java:160) ~[bundleFile:4.3.3]
        at org.jivesoftware.smack.SynchronizationPoint.checkIfSuccessOrWaitOrThrow(SynchronizationPoint.java:131) ~[bundleFile:4.3.3]
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:944) ~[bundleFile:4.3.3]
        at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:417) ~[bundleFile:4.3.3]
        at org.openhab.binding.xmppclient.internal.XMPPClient.connectionClosedOnError(XMPPClient.java:149) [bundleFile:?]
        at org.jivesoftware.smack.AbstractXMPPConnection.callConnectionClosedOnErrorListener(AbstractXMPPConnection.java:1324) [bundleFile:4.3.3]
        at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$800(XMPPTCPConnection.java:154) [bundleFile:4.3.3]
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$2$1.run(XMPPTCPConnection.java:991) [bundleFile:4.3.3]
        at java.lang.Thread.run(Thread.java:834) [?:?]

Possible Solution

One Solution could be that the connection timeout or some kind of retry limit is configurable Another one would be to try to reconnect every 5 - 15 Minutes

Steps to Reproduce (for Bugs)

  1. Configure xmpp binding
  2. Reboot XMPP Server or make it unreachable for more than 5 seconds

Context

My current workaround is to restart the binding every morning via an cronjob. This works pretty well, but yeah daily restarts are not the best solution. Also for other ppl such an timeout/unreachable scenario could happen any time.

Your Environment

YokaiRick commented 3 years ago

Just wanted to say, that its my first time reporting here, so if i missed sth relavent please reach out to me. And thanks for working on openhab i rly love it!

Nuesel commented 2 years ago

Hello all, I have a similar issue here. After rebooting my Ubuntu server, the xmpp binding sometimes has problems in DNS resolving. Instead of retrying after some time, it shuts down itself. In this case, the xmpp binding is not useable until restarting it. It would be nice, if the binding tries to reconnect after some time.

2021-08-30 01:12:35.255 [INFO ] [org.openhab.ui.internal.UIService ] - Started UI on port 8080 2021-08-30 01:12:41.191 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started. 2021-08-30 01:12:45.819 [INFO ] [internal.ModuleHandlerFactoryStarter] - WebPushNotificationModuleHandlerFactory started by ModuleHandlerFactoryStarter 2021-08-30 01:12:46.154 [INFO ] [hab.ui.habot.tile.internal.HABotTile] - Started HABot at /habot 2021-08-30 01:12:46.282 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel 2021-08-30 01:12:46.452 [WARN ] [software.smack.tcp.XMPPTCPConnection] - shutdown java.lang.NullPointerException: null at org.jivesoftware.smack.tcp.XMPPTCPConnection.shutdown(XMPPTCPConnection.java:538) [bundleFile:4.3.3] at org.jivesoftware.smack.tcp.XMPPTCPConnection.instantShutdown(XMPPTCPConnection.java:507) [bundleFile:4.3.3] at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:426) [bundleFile:4.3.3] at org.openhab.binding.xmppclient.internal.XMPPClient.connect(XMPPClient.java:87) [bundleFile:?] at org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler.doConnect(XMPPClientHandler.java:90) [bundleFile:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?] at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?] at java.lang.Thread.run(Thread.java:834) [?:?] 2021-08-30 01:12:46.471 [INFO ] [t.internal.handler.XMPPClientHandler] - XMPP connection error org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: 'gruenbaer.net:5222' failed because: java.net.UnknownHostException: gruenbaer.net: Temporary failure in name res olution at org.jivesoftware.smack.SmackException$ConnectionException.from(SmackException.java:292) ~[bundleFile:4.3.3] at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguratio n(XMPPTCPConnection.java:658) ~[bundleFile:4.3.3] at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(XMPPTCPConnection.java:938) ~[bundleFile:4.3.3] at org.jivesoftware.smack.AbstractXMPPConnection.connect(AbstractXMPPConnection.java:417) ~[bundleFile:4.3.3] at org.openhab.binding.xmppclient.internal.XMPPClient.connect(XMPPClient.java:87) ~[bundleFile:?] at org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler.doConnect(XMPPClientHandler.java:90) [bundleFile:?] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?] at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?] at java.lang.Thread.run(Thread.java:834) [?:?] 2021-08-30 01:42:45.017 [WARN ] [jivesoftware.smackx.ping.PingManager] - XMPPConnection was not authenticated

lsiepel commented 1 year ago

I just made a new draft for XMPPclient binding. If possible could you test and let me know if the problem you have still exists? openHAB 3.4.2: https://1drv.ms/u/s!AnMcxmvEeupwjqVFDy9C1Eh--QOA5g?e=P1pKSa openHAB 4.0.0: https://1drv.ms/u/s!AnMcxmvEeupwjqVFDy9C1Eh--QOA5g?e=7j3aZM

source is here: https://github.com/lsiepel/openhab-addons/tree/xmpp-reconnect

If the problem remains or you encounter some regression, providing a debug log would help me fix it.

It has two changes:

YokaiRick commented 1 year ago

uhh nice, i actually thought if i should tackle the problem in my next bigger free time slot. gonna check it out, but it could take some time, dunno if i can test sth before weekend. just for your info

YokaiRick commented 1 year ago

I can't test it 100% cause the xmpp server is does not restart every day anymore, but a 180 sec reconnect interval sounds reasonable. why not give it a try and make pull request :)

lsiepel commented 1 year ago

I’d like to have it tested (atleast for regression) before I file it as PR.

you could simate the test by dropping the connection (temporary firewall block or disable internet for a minute )

YokaiRick commented 1 year ago

Finally had time to spin up a test instance. mhh i'm currently getting this dependency error while using your build for 3.4.2

- Error while starting bundle: file:/usr/share/openhab/addons/org.openhab.binding.xmppclient-3.4.2-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.xmppclient [285]
  Unresolved requirement: Import-Package: org.jivesoftware.smack; version="[4.3.0,5.0.0)"

mhh it did mention version 4.3.0-5.0.0.. but there is only an very old version at mavenrepository.. shouldn't it point to igniterealtime's smack?

lsiepel commented 1 year ago

I think i have seen this somewhere before, guess this is a bug in oh core, that won't load the dependencies when a jar is dropped in. Let me check for a solution. Maybe @jlaur has some suggestions.

jlaur commented 1 year ago

I think i have seen this somewhere before, guess this is a bug in oh core, that won't load the dependencies when a jar is dropped in. Let me check for a solution. Maybe @jlaur has some suggestions.

I believe it can be fixed by dropping the required packages in the addons directory also. At least this is how I managed to get the JDBC persistence service working with the MySQL driver.

jlaur commented 1 year ago

I believe it can be fixed by dropping the required packages in the addons directory also. At least this is how I managed to get the JDBC persistence service working with the MySQL driver.

See also: https://community.openhab.org/t/oh4-dependency-bundles-not-included-anymore/144288

lsiepel commented 1 year ago

@YokaiRick did you have the oppertunity to test it?

Bart1478 commented 1 year ago

Hi,

I'm sure not on the right place but i also encounter some xmpp issues with openhab 3.4.2. Have asked several times in the openhab community but no help. So please have you some time to help me out?

This is my problem. When starting openhab a connection with the Xmpp server was succesful but after 30 minutes the connection is aborted and reestablished again... but i have a feeling that only the first x seconds of the rebuilt connection there is some communication possible?

lsiepel commented 1 year ago

Please start a new issue on github with debug logs, versions and all details about the issue. Not sure if i can help you out, but that is the best starting point.

YokaiRick commented 1 year ago

@lsiepel its merged, but not relased yet ^^v i did try to build your version, i also downloaded your version, but then i ended in a dependency hell. Sadly I'm not a java dev and never build a java application before, so... i'm stuck ^^v

how about we close this issue, and if i see that it reapers, i'll repoen the issue?

lsiepel commented 1 year ago

I’ll try to get you a working jar/kar for 4.0m1 It is not merged so it will not become available unless it is tested. Thanks for your first efforts. I hope to get you the files tomorrow.