简体   繁体   English

Android上的MQTT Eclipse Paho客户端,断开挂起并永不完成

[英]MQTT Eclipse Paho client on Android, disconnect hangs and never completes

I'm using MQTT in an android application, using the latest jar as found on the Eclipse Paho page. 我在Android应用程序中使用MQTT,使用Eclipse Paho页面上的最新jar。

I'm manually checking the connection by sending occasional publishes under a QOS of 1, and if it's not delivered under a certain timeout I disconnect MQTT and reconnect. 我通过在QOS为1的情况下发送偶尔发布来手动检查连接,如果在某个超时下没有发送,我断开MQTT并重新连接。 When the data connection is lost then regained I also force a reconnect. 当数据连接丢失然后重新获得时我也强制重新连接。

The issue is that the disconnect method hangs the thread and never completes - even with a zero or negative timeout. 问题是disconnect方法挂起线程并且永远不会完成 - 即使是零或负超时。 It's supposed to have an internal timeout of 30 seconds but it goes long past this and never completes. 它应该有30秒的内部超时,但它会超过这个并且永远不会完成。

The MqttClient object needs to be disconnected otherwise it sits in the background chewing up data. MqttClient对象需要断开连接,否则它会在后台咀嚼数据。 What I'm now doing is spinning off a seperate thread to disconnect MQTT then creating a new MqttClient entirely. 我现在正在做的是分离一个单独的线程来断开MQTT,然后完全创建一个新的MqttClient。 It stops using data but it's a bad solution as the new thread just hangs instead. 它停止使用数据,但这是一个糟糕的解决方案,因为新线程只是挂起。

Any ideas? 有任何想法吗?

Edit: On further investigation it seems to be blocking on attempting to stop CommsReceiver at line 70: 编辑:进一步调查似乎阻止尝试在第70行停止CommsReceiver:

public void stop() throws IOException {
    synchronized (lifecycle) {
        //@TRACE 850=stopping receiver
        trace.trace(Trace.FINE,850);
        if (running) {
            running = false;
            try {
                //@TRACE 851=stop: wait on lifecycle
                trace.trace(Trace.FINE,851);
                // Wait for the thread to finish.
                lifecycle.wait(); // THREAD HANGS //
            }
            catch (InterruptedException ex) {
            }
        }
    }
}

The problem is due to a timing window in the stable version of the paho client, if you use the code in the develop branch of the paho repository. 问题是由于paho客户端的稳定版本中的计时窗口,如果您使用paho存储库的develop分支中的代码。 You shouldn't come across this problem because it is marked as fixed in this bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=394066 although its not the stable branch I have found the develop branch to be reliable. 你不应该遇到这个问题,因为它在这个bug中被标记为已修复https://bugs.eclipse.org/bugs/show_bug.cgi?id=394066虽然它不是稳定的分支我找到了开发分支是可靠。

There is a bug filed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=394066 (probably by the OP of this question, info for @Vipul). 这里有一个错误: https ://bugs.eclipse.org/bugs/show_bug.cgi?id = 394066(可能是这个问题的OP,@ Vipul的信息)。 The status says resolved so see when the new JAR is available with the fix and use that 状态说明已解决,因此请查看新JAR何时可用于修复并使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM