nfscarbon / asmack

Automatically exported from code.google.com/p/asmack
Other
0 stars 0 forks source link

ReconnectionManager problems #41

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What are you doing to produce the error?
1. Open connection with connConfig.setReconnectionAllowed(true);
2. Swicth flight mode on
3. Switch flight mode off

What is the expected output?
Connection is reopened automatucally within 10 sec

What do you see instead? (Please attach a debug enabled logcat)
Connection is not reesteblished 

What version of aSmack / Android / Device do you use?
asmack-issue15.jar
android 2.2
HTC Desire

What server do you use? Is there a public server to reproduce the problem?
gtalk

What else might help us to reproduce and hunt down the problem?
After looking at the code it turned out that static constructor of 
ReconnectionManager is never called.

Following code fixes this problem 
Constructor<?>[] c = ReconnectionManager.class.getConstructors();

Looks like android avoids calling static unless the class is used in runtime.

But the break of connection causes ConnectionListener.connectionClosedOnError 
to be called twice 
java.io.IOException: Write error: I/O error during system call, Broken pipe
        at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativewrite(Native Method)
        at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.access$600(OpenSSLSocketImpl.java:55)
        at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:583)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:175)
        at java.io.BufferedWriter.flush(BufferedWriter.java:158)
        at org.jivesoftware.smack.PacketWriter.writePackets(PacketWriter.java:195)
        at org.jivesoftware.smack.PacketWriter.access$000(PacketWriter.java:42)
        at org.jivesoftware.smack.PacketWriter$1.run(PacketWriter.java:78)

java.io.IOException: Read error: I/O error during system call, Connection timed 
out
        at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativeread(Native Method)
        at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.access$300(OpenSSLSocketImpl.java:55)
        at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:542)
        at java.io.InputStreamReader.read(InputStreamReader.java:275)
        at java.io.BufferedReader.fillBuf(BufferedReader.java:155)
        at java.io.BufferedReader.read(BufferedReader.java:348)
        at org.kxml2.io.KXmlParser.peek(KXmlParser.java:931)
        at org.kxml2.io.KXmlParser.pushText(KXmlParser.java:881)
        at org.kxml2.io.KXmlParser.nextImpl(KXmlParser.java:354)
        at org.kxml2.io.KXmlParser.next(KXmlParser.java:1385)
        at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:326)
        at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
        at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:71)

Thus this code in ReconnectionManager
 public void connectionClosedOnError(Exception e) {
        done = false;
        if (e instanceof XMPPException) {
            XMPPException xmppEx = (XMPPException) e;
            StreamError error = xmppEx.getStreamError();

            // Make sure the error is not null
            if (error != null) {
                String reason = error.getCode();

                if ("conflict".equals(reason)) {
                    return;
                }
            }
        }

        if (this.isReconnectionAllowed()) {
            this.reconnect();
        }
    }
produces are two threads.

On of these threads fails with 
12-12 01:42:34.642: ERROR/AndroidRuntime(7830): FATAL EXCEPTION: Smack 
Reconnection Manager
        java.lang.IllegalThreadStateException: Thread already started.
        at java.lang.Thread.start(Thread.java:1331)
        at org.jivesoftware.smack.PacketWriter.startup(PacketWriter.java:119)
        at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:603)
        at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:565)
        at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:991)
        at org.jivesoftware.smack.ReconnectionManager$2.run(ReconnectionManager.java:122)

wich is not even processed in catch block:

// Makes a reconnection attempt
                        try {
                            if (ReconnectionManager.this.isReconnectionAllowed()) {
                                connection.connect();
                            }
                        }
                        catch (XMPPException e) {
                            // Fires the failed reconnection notification
                            ReconnectionManager.this.notifyReconnectionFailed(e);
                        } 

Thus there 2 changes need to be apllyed:
1. "Touch" ReconnectionManager class somwhere (e.g. in 
ConnectionConfig.setReconnectionAllowed() ) to ensure static constructor is 
executed.
2. Update ReconnectionManager.isReconnectionAllowed() to verify that there is 
no active reconnection threads.

Original issue reported on code.google.com by Konstant...@gmail.com on 11 Dec 2010 at 10:52

GoogleCodeExporter commented 8 years ago
this issue is not present in smack 3.1.0

Original comment by simon.ma...@gmail.com on 20 May 2011 at 1:41

GoogleCodeExporter commented 8 years ago
issue still happen! please fix it. thanks

Original comment by wayl...@gmail.com on 6 Oct 2011 at 4:51

GoogleCodeExporter commented 8 years ago
Hi I am using asmack for developing android IM.I am facing problem on message 
receiving after reconnect network connection.
I am using a broadcast receiver with action as 
android.net.conn.CONNECTIVITY_CHANGE > to know is the internet reconnection 
(wifi or 3g)I have a service for listen incoming packets. When my device 
reconnect with internet from above broadcast active and hear a internet 
available that time I reconnect my application with Tigase Server and then I 
re-login on server that is fine. Same time I also again attaching listeners of 
my service so they can listen incoming packets. But When I send message it 
going to user B but User B sending me messages on my side its not receiving. on 
user B side it showing that user A Connected with new connection and also 
showing presence.Like to hear where I am doing wrong. . 

Original comment by tonasiri...@gmail.com on 30 Jun 2012 at 11:02

GoogleCodeExporter commented 8 years ago
Saw this today, using asmack-2010.05.07.jar.
The phone was sitting on my desk; I don't whether or not it was asleep.

Original comment by rstin...@gmail.com on 22 Oct 2013 at 6:38

GoogleCodeExporter commented 8 years ago
android.os.Build.MODEL:ADR6400L
android.os.Build.VERSION.RELEASE:4.0.4

Thread:
  Name: Smack Reconnection Manager
  Id: 2237
  State: RUNNABLE
java.lang.IllegalThreadStateException: Thread already started.
    at java.lang.Thread.start(Thread.java:1061)
    at org.jivesoftware.smack.PacketReader.startup(PacketReader.java:103)
    at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:606)
    at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:565)
    at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:991)
    at org.jivesoftware.smack.ReconnectionManager$2.run(ReconnectionManager.java:122)

Original comment by rstin...@gmail.com on 22 Oct 2013 at 6:42