1

I get network errors running on android. These do not appear in simulator or ios builds. The errors appears about 75% of the time and then will work correctly for one time. I did some debugging and the network call returns a 0 for response code and null for response content.

I've attached the call below for my get command. This code has not changed in many years (3?). I tried 2 different applications now and both exhibit the same behavior.

I've tried going back to older builds but my 'pro' license only allows me to go back to 1 latest???

I know its not the server as it works for iOS and simulator and 2 different application. I have been unable to figure this out.

An suggestions? I tried to use the new Rest, but it doesn't find the class (i went to latest).

public int doGet(final String url) {

    if ( Display.getInstance().isEdt() ){
        Log.e("*** Performing a GET network call on the EDT");
    }

    final ConnectionRequest request = new ConnectionRequest() {
        @Override
        protected void handleException(Exception err) {
            if (Dialog.show("Connection error",
                    "Check your internet connection", "Retry", "Exit")) {
                Display.getInstance().exitApplication();
            } else {
                retry();
            }
        }
    };

    request.setUrl(url);
    request.setPost(false);
    request.setFollowRedirects(false);
    request.setReadResponseForErrors(true);
    request.setSilentRetryCount(1);

    request.addResponseCodeListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            Log.d("Response code ResponseCodeListener, setting to -1");
            responseCode = -1;
        }
    });
    request.addResponseListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            Log.e("Response listener action for GET performed " ); 
            ConnectionRequest cr = (ConnectionRequest) evt.getSource();
            responseCode = cr.getResponseCode();
            Log.e("Response listener action for GET performed: " + cr.getResponseCode() ); 
            if (cr.getResponseCode() == 200) {
                responseData = new String(cr.getResponseData());
            } else {
                Log.e("Response code: " + cr.getResponseCode() + " of " + cr.getUrl() );
            }
        }
    });
    // request will be handled asynchronously
    NetworkManager.getInstance().setTimeout(15000);

    synchronized (lock) {
        depth++;
    }
    try {
        request.setDuplicateSupported(true);
        NetworkManager.getInstance().addToQueueAndWait(request);
    } finally {
        synchronized (lock) {
            depth--;
        }
    }

    Log.d("Response: {0}  {1}", responseCode, responseData);
    return responseCode;
}

Log entries: 02-11 10:08:26.932 20250-20326/? D/Word Time: [Thread-18] 0:0:2,486 - Get: /jgame/game/6647?tkn=08F0D0B4E7EE80370B982DBEA261500ADB53266C1847175152-1461100

02-11 10:08:26.933 20250-20326/? D/Word Time: [Thread-18] 0:0:2,488 - Calling: GET   http://server.wordtimelive.xyz/jgame/game/6647?tkn=08F0D0B4E7EE80370B982DBEA261500ADB53266C1847175152-1461100

02-11 10:08:26.934 20250-20326/? D/Word Time: [Thread-18] 0:0:2,489 - Get: http://server.wordtimelive.xyz/jgame/game/6647?tkn=08F0D0B4E7EE80370B982DBEA261500ADB53266C1847175152-1461100

02-11 10:08:27.207 20250-20326/? D/Word Time: [Thread-18] 0:0:2,762 - Response: 0  null

02-11 10:08:27.209 20250-20326/? D/Word Time: [Thread-18] 0:0:2,763 - content null of GET: http://server.wordtimelive.xyz/jgame/game/6647?tkn=08F0D0B4E7EE80370B982DBEA261500ADB53266C1847175152-1461100
sam
  • 165
  • 7
  • That generally means the request is stuck in queue but on device these things are always notoriously hard to capture. I suggest trying a tool like wireshark so you can see the request/response data https://stackoverflow.com/questions/9555403/capturing-mobile-phone-traffic-on-wireshark – Shai Almog Feb 12 '18 at 04:12
  • @ShaiAlmog I have a test program now that shows this issue in the simulator. Apparently the simulator is showing it but was not enough for me to see it. When I run against 3.7 or lower it works fine, when I run with latest it shows the issue. How can I send this you your support team? Its a small isolated test. I cant add attachments to this. – sam Feb 12 '18 at 13:09
  • Try checking against 3.8 but if you have a test case that would help. If you can reproduce this in the simulator make sure to use the `NetworkMonitor` to see what happens under the hood. I also suggest doing all of this on the EDT and not on a separate thread. The NetworkMonitor has network threads within it so invoking it on the EDT shouldn't be a problem. – Shai Almog Feb 13 '18 at 05:00
  • I am using against Latest, is this 3.8? – sam Feb 13 '18 at 12:39
  • I was using the older configuration screen. Unfortunately the issue is still in 3.8. I opened a ticket in github for this issue and it is reproducible with the simulator. – sam Feb 14 '18 at 00:57
  • I figured out the issue. Its due to a ConcurrentModificationException in the cookie handling. I believe it is because my server is sending cookies with expiration dates in the format of: 14-Feb-18 03:13:52 GMT instead of the 4 character year. Wiki says (https://en.wikipedia.org/wiki/HTTP_cookie#Expires_and_Max-Age) it is in 2 or 4 character years. Not exactly sure why it causes concurrent mod exception. The solution for me: request.setCookiesEnabled(false); However this looks like a regression in the network framework from the recently changed cookie handling. – sam Feb 14 '18 at 03:17
  • Yes we changed that a while ago. Do you have the stack trace of the exception? – Shai Almog Feb 14 '18 at 05:22
  • java.util.ConcurrentModificationException at java.util.Hashtable$Enumerator.next(Hashtable.java:1378) at com.codename1.impl.CodenameOneImplementation.purgeOldCookies(CodenameOneImplementation.java:4171) at com.codename1.impl.CodenameOneImplementation.addCookie(CodenameOneImplementation.java:4208) at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:713) at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282) at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176) – sam Feb 14 '18 at 12:59

1 Answers1

0

Thanks for the help in tracking this. Steve fixed the concurrent modification exception in this commit https://github.com/codenameone/CodenameOne/commit/685172518e00a7b846993bbc35967cf49a0bc611

Based on the description it sounds like this is indeed the problem you were experiencing. It will be in the servers tomorrow (Friday February 16th 2018) and you can verify it.

Shai Almog
  • 49,879
  • 5
  • 30
  • 57
  • Thanks Shai, would I do this by getting the latest if in the dropdown? – sam Feb 15 '18 at 13:45
  • This weekend we'll release an IDE plugin update too but normally updates should arrive seamlessly for these sort of things. – Shai Almog Feb 16 '18 at 05:08