[showstopper] second time call ConnectionRequest with same data & no server always hangs app

140 views
Skip to first unread message

eos

unread,
Aug 31, 2013, 7:34:43 PM8/31/13
to codenameone...@googlegroups.com
I have a login form which simple calls a get on a server and reads the JSON response.  If the server is running, all is good.

If the server is not running, then you get an exception which throws a dialog to CANCEL or RETRY (not my dialog). This is odd as I can't catch this exception, so cant do anything about it.

If I then hit cancel, then the login button again, i was seeing a message on the console "Duplicate entry detected" then the app hangs with the spinning infnite dialog - there is no event I can use to stop it.
If I hit return, then login button again, I was seeing the message: Duplicate entry in the queue: userclasses.StateMachine$2: userclasses.StateMachine$2@31333a then the app hangs  with the spinning infnite dialog - there is no event I can use to stop it.

I tried adding this:

con.setDuplicateSupported(true);

But now the app just hangs on the second send without the "Duplicate" message appearing in the console.

The code is simple, and goes like this:

   @Override
    protected void onLogin_ButtonLonginAction(Component c, ActionEvent event) {
        // do some stuff.
ConnectionRequest con = new ConnectionRequest() {
     @Override
    protected void postResponse(){
     // check the JSON data...
    
    if (name != null && !"".equals(name)) {

    Display.getInstance().callSerially(new Runnable() {
      public void run() {
      showForm("Main", null);
      }
    });
    }
    }
   
    @Override
    protected void readResponse(InputStream input) throws IOException {
                      // read the json data.
     };
       
    };
   
    con.setPost(false);
    con.setUrl(Settings.getUrl() + "/player/login");
    con.addArgument("user", usreName);
    con.addArgument("pass", password);
    con.setTimeout(30*1000);

    InfiniteProgress prog = new InfiniteProgress();
    Dialog dlg = prog.showInifiniteBlocking();
    con.setDisposeOnCompletion(dlg);
     con.setDuplicateSupported(true);
   
    try  {
    NetworkManager.getInstance().addToQueueAndWait(con);
    } catch (Exception e) {
    dlg.dispose();
        Dialog.show("Connection Problem", "Sorry, there was an error connecting to the server", "ok", null);
    }
    }

In this case, no exception is being caught my my code above.


Full stack trace when DuplicateSupported not set:

java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:3964)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:292)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:242)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:3964)
at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:292)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:242)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Duplicate entry in the queue: userclasses.StateMachine$2: userclasses.StateMachine$2@31333a

Full stack trace when duplicateSupported set to true:

If I hit "retry", there is no stack trace.  It just hangs the app.

If I hit cancel, there is stack trace, it also just hangs the app.

Shai Almog

unread,
Sep 1, 2013, 12:39:46 AM9/1/13
to codenameone...@googlegroups.com
Override:
    protected void handleErrorResponseCode(int code, String message)


And:
    protected void handleException(Exception err) {

Instead of invoking super just write your own error handling code.

You can do this globally in the NetworkManager by using the add error handler method.

Simon Hobbs

unread,
Sep 1, 2013, 4:07:34 AM9/1/13
to codenameone...@googlegroups.com

Thanks for the advice.  I added both these. 

 

Should it not auto dispose the dlg when it gets an exception, the same as when it comples?  Otherwise lots of apps will get spinning wheels of death…

 

e.g. with this:

 

                InfiniteProgress prog = new InfiniteProgress();

                Dialog dlg = prog.showInifiniteBlocking();

                con.setDisposeOnCompletion(dlg);

 

 

I am guessing I Should add this:

 

                                this.getDisposeOnCompletion().dispose();

 

to both handleErrorResponseCode and handleException, is that the correct approach?

 

Thanks!

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/fDWYWXeSCsc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/5191a09f-05bd-41de-899d-42618d012b92%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

eos

unread,
Sep 1, 2013, 4:11:23 AM9/1/13
to codenameone...@googlegroups.com
I just added these, with this.getDisposeOnCompletion().dispose(), and it still hangs with the spinning wheel of death.  So something else is happening which the two overriddend error handles + catching exceptions from the NetworkManager dont catch, unfortunately.
Any ideas?

Shai Almog

unread,
Sep 1, 2013, 4:31:57 AM9/1/13
to codenameone...@googlegroups.com
These are not invoked on the EDT, you should wrap your call to dispose your progress dialog with call serially.

eos

unread,
Sep 1, 2013, 8:56:15 AM9/1/13
to codenameone...@googlegroups.com
that seems to have fixed the hang - nice work!
Reply all
Reply to author
Forward
0 new messages