Jelly Bean network service not working.

Can any of your testers access the adb logcat tool to see what the console log is reporting?  You can put in some prints and see what’s going on.   There are some reports that network requests time out on 4.3 but we can’t reproduce the problem.  Your code tests for isError, but you don’t seem to be showing that error anywhere other than the console log.

I have had a log from one user (let’s talk about the GC later):

09-27 10:38:40.091: I/Corona(4901): service.post url:    app/messagecompose.php    params:    id=605&ti=&f=605&t=1&m=message test&ct=0

09-27 10:38:40.111: I/System.out(4901): ERROR: None

09-27 10:38:40.121: I/Corona(4901): service.postListener Network error!

09-27 10:38:53.361: D/dalvikvm(4901): GC_FOR_ALLOC freed 527K, 47% free 8053K/15104K, paused 24ms, total 25ms

09-27 10:39:55.071: D/dalvikvm(4901): GC_FOR_ALLOC freed 514K, 47% free 8050K/15104K, paused 21ms, total 21ms

I am aware that the code I pasted is just logging out the error, this is not production code.

I learned the hard way. Do not trust that every call you make to the internet will be successful. If there is an error you should check it and deal with it accordingly. Now on top of that I learned to never assume the network is down when it errors abnormally.

As Rob mentioned, I have found that on 4.3 and perhaps less so on 4.2 that the network will randomly just instantly report no connection was made giving a -1 error code. Code a retry mechanism for your network requests. If you get this -1 error code, retry the request. I have found it can take sometimes 1-3 retries before it works. Since coding a retry mechanism myself I have had no failed network requests unless the network is truly unavailable.

I will kick in some retries and see how the app performs.

Are you suggesting infinite retries, perhaps with increasing delays, or did you just give up with after 10 or so?

Love the “ERROR: None” output in that log!

Thanks,

I currently have two different pieces of code for retries.

My normal retry code is when there is a real internet time-out. It retries every 5 seconds until it goes through (so yes forever).

For this weird bug with 4.3 I retry 5 times with a 2 second delay between each. Then I let my normal retry code kick in. I have never had the quick 5 retries fail with this specific bug. It’s almost like the network has went into sleep mode and needs to wake-up before it will work.

While we would want network programming to be easy, the reality is it’s not.  Web servers are down from time to time. Servers get busy.  The platform you’re running has various level of hardness, timeout settings.   Packets route through dozens of routers to get from your device to the server and back.  There are plenty of opportunities for packets to get lost and handling errors is something you have to do.  You can choose to just give up or you can retry.

Personally I would not not try forever.  Maybe 5-10 tries.  If the server is down for real, or the app is in airplane mode or your 3G just stinks, you don’t want to lock your app up over this.  You probably should also have a graceful way of handling when you can’t get the data as well.

Are you able to test yourself?  Out of how many users do you have total?  Show us some code?  

I cannot test myself, I haven’t been able to upgrade my test device to jelly bean.

I have about 10 users testing the android, all good apart from 3 on jelly bean.

All my network requests are wrapped in a service object, and have been working without any error on iphones and most androids:

service = {} service.postListener = function( event )     if ( event.isError ) then         print( "service.postListener Network error!")     else         service.result = json.decode( event.response )         service.callback( service.result )     end end service.post = function( file, vars, callback )     service.callback = callback     local params = {         body = "id=" .. user.id .. "&" .. vars     }     local url = domain .. file     network.request( url, "POST", service.postListener, params ) end local function onSaveResult( response )     print ( "onSaveResult - response", response.error ) end local function saveResult()     local file = "app/save\_result.php"     local vars = "mode=" .. game.mode .. "&ci=" .. game.ci .. "&gp=" .. user.id .. "," .. game.opponent.id .."&w=" .. game.winner     service.post( file, vars, onSaveResult ) end  

Can any of your testers access the adb logcat tool to see what the console log is reporting?  You can put in some prints and see what’s going on.   There are some reports that network requests time out on 4.3 but we can’t reproduce the problem.  Your code tests for isError, but you don’t seem to be showing that error anywhere other than the console log.

I have had a log from one user (let’s talk about the GC later):

09-27 10:38:40.091: I/Corona(4901): service.post url:    app/messagecompose.php    params:    id=605&ti=&f=605&t=1&m=message test&ct=0

09-27 10:38:40.111: I/System.out(4901): ERROR: None

09-27 10:38:40.121: I/Corona(4901): service.postListener Network error!

09-27 10:38:53.361: D/dalvikvm(4901): GC_FOR_ALLOC freed 527K, 47% free 8053K/15104K, paused 24ms, total 25ms

09-27 10:39:55.071: D/dalvikvm(4901): GC_FOR_ALLOC freed 514K, 47% free 8050K/15104K, paused 21ms, total 21ms

I am aware that the code I pasted is just logging out the error, this is not production code.

I learned the hard way. Do not trust that every call you make to the internet will be successful. If there is an error you should check it and deal with it accordingly. Now on top of that I learned to never assume the network is down when it errors abnormally.

As Rob mentioned, I have found that on 4.3 and perhaps less so on 4.2 that the network will randomly just instantly report no connection was made giving a -1 error code. Code a retry mechanism for your network requests. If you get this -1 error code, retry the request. I have found it can take sometimes 1-3 retries before it works. Since coding a retry mechanism myself I have had no failed network requests unless the network is truly unavailable.

I will kick in some retries and see how the app performs.

Are you suggesting infinite retries, perhaps with increasing delays, or did you just give up with after 10 or so?

Love the “ERROR: None” output in that log!

Thanks,

I currently have two different pieces of code for retries.

My normal retry code is when there is a real internet time-out. It retries every 5 seconds until it goes through (so yes forever).

For this weird bug with 4.3 I retry 5 times with a 2 second delay between each. Then I let my normal retry code kick in. I have never had the quick 5 retries fail with this specific bug. It’s almost like the network has went into sleep mode and needs to wake-up before it will work.

While we would want network programming to be easy, the reality is it’s not.  Web servers are down from time to time. Servers get busy.  The platform you’re running has various level of hardness, timeout settings.   Packets route through dozens of routers to get from your device to the server and back.  There are plenty of opportunities for packets to get lost and handling errors is something you have to do.  You can choose to just give up or you can retry.

Personally I would not not try forever.  Maybe 5-10 tries.  If the server is down for real, or the app is in airplane mode or your 3G just stinks, you don’t want to lock your app up over this.  You probably should also have a graceful way of handling when you can’t get the data as well.

This bug is still here and should not be happening like this.

I can send 3 network requests, then the next 3 will fail, then the next 3 work again and so on… Retry logic on every request adds a lot of overhead when there shouldn’t be, since this is not needed on iphone nor the emulator.

Strange part of this is, this bug doesnt happen on android emulator, only on real devices.

Could it be any http header missing? Are there any news about this?

There have been a few fixes to android networking in recent daily builds.  They will be in the new public build coming soon.

Rob

I have made a topic about my current issue which might or might not be related to this same issue, if you can take a look.

http://forums.coronalabs.com/topic/45069-android-network-requests-random-no-responses-and-no-response-with-https/

Hopefully that new build fixes some of this if it is corona related, I will be trying out native android code just to make sure it is not corona related.

This bug is still here and should not be happening like this.

I can send 3 network requests, then the next 3 will fail, then the next 3 work again and so on… Retry logic on every request adds a lot of overhead when there shouldn’t be, since this is not needed on iphone nor the emulator.

Strange part of this is, this bug doesnt happen on android emulator, only on real devices.

Could it be any http header missing? Are there any news about this?

There have been a few fixes to android networking in recent daily builds.  They will be in the new public build coming soon.

Rob

I have made a topic about my current issue which might or might not be related to this same issue, if you can take a look.

http://forums.coronalabs.com/topic/45069-android-network-requests-random-no-responses-and-no-response-with-https/

Hopefully that new build fixes some of this if it is corona related, I will be trying out native android code just to make sure it is not corona related.