network.request sending multiple requests at the same time on android

Hi,

today we have found and confirmed a serious [from our perspective] issue on android [not sure about ios].

When a SINGLE network.request call is made, our web server gets 2 requests one after another. The time difference is several milliseconds.

The requests is processed twice and two responses are sent, in Corona, our callback function is called twice.

This does not happen all the time!

This clearly is an issue with HttpClient retry handling on Android:

http://stackoverflow.com/questions/8949487/duplicate-requests-from-httpclient

I can see the response header with:

X-Android-Sent-Millis

element, and two of the responses have the value with a few milliseconds difference.

This is a very serious problem for us, because we use IAP verification on server and now our response comes multiple times and users are awarded multiple times. Also synchronization of game progress can get f**ked up because of this [multiple lives are removed or added].

I have Enterprise license, but I cannot implement the fix to change the default strategy of the HttpClient, because it’s not a singleton.

Is there anyway I could workaround this problem?

Are you getting a 301 or 302 redirect?

Are you sure you don’t have this on a button thats getting multiple phases (like began and ended)?

Rob

Have you double and triple checked that you’re not calling the function twice? Throw a print() right on top of the network.request() to verify, if you haven’t already. I was experiencing something similar recently, and it was a good old fashioned case of forgetting to check the different phases of a “touch” event.

Yes, I’m sure the request is called once, I’ve got plenty of logs in there.

The issue is most common when internet connection is crappy, but it happens even on wifi.

Weirdest thing is that the time difference between requests are so close one to another.

My current workaround is to add request identifier and filter them out on the server.

We made a test yesterday and after switching phone to mobile network with bad reception, over half of the requests were doubled, some were tripled.

The request I am sending is not triggered by a button.

Oh I forgot, I am not getting any errors nor redirects. 

It’s a bit weird, I admit. Especially the fact that the callback is called twice, I don’t know lua nor luasocket good enough to make assumptions on how callback function is stored and handled, but after some investigation I am pretty sure it’s connected to the “issue” on android.

Engineering will need a bug report with code that shows the problem.  Please file a bug report.  The project needs to be complete (main.lua, build.settings, config.lua and any resources needed to run the app.  Put it in a .zip file and use the Report a bug link at the top.

Please post the Case ID # that gets emailed to you back here.

Rob

Rob,

no problem, I will create an issue, but I will also need some support about… how to create it?

the easiest way would be to include in main a single network.request, which in many cases does the job, but we all know in most cases it works fine so… what do I include in order to make this issue meaningful?

Before I send a request, I generate a timestamp with milliseconds and the same timestamp comes to me 2-3 times in a row, so I know I am not imagining things :slight_smile:

Thanks

Krystian

I would just note that you may have to try it several times to get it to fail.  Perhaps ad a button that triggers the network request so the engineer can just tap it repeatedly until he can see the issue.

Rob

You might want to setup an alternate script/web page that doesn’t catch the error, or responds back something to indicate that it’s happening multiple times. This may be the tricky part, is showing them it’s happening.

Rob

I’m very interested to see what this is caused by… I’m about to release an app that relies a lot of its functionality on a php based REST API… though I never experienced this issue myself, it would be pretty bad if it started happening just as I release the app.

krystian, can you in the meantime at least post some specifics of what you’re testing the app on? i am testing on a couple of samsung, HTC and Sony devices and never ran into the issue yet…

Right,

I’ll get back to it on monday.

I need to find something that would throttle the internet connection so that this is possible to reproduce it.

K

@brdenton:

All of android devices we own have the same issue. From what I can see on the internet it’s because all of Android versions use HttpClient package which was forked from a beta version, back when it had 3 retries by default. Nowadays it has 0, but this was never rebased.

Are you getting a 301 or 302 redirect?

Are you sure you don’t have this on a button thats getting multiple phases (like began and ended)?

Rob

Have you double and triple checked that you’re not calling the function twice? Throw a print() right on top of the network.request() to verify, if you haven’t already. I was experiencing something similar recently, and it was a good old fashioned case of forgetting to check the different phases of a “touch” event.

Yes, I’m sure the request is called once, I’ve got plenty of logs in there.

The issue is most common when internet connection is crappy, but it happens even on wifi.

Weirdest thing is that the time difference between requests are so close one to another.

My current workaround is to add request identifier and filter them out on the server.

We made a test yesterday and after switching phone to mobile network with bad reception, over half of the requests were doubled, some were tripled.

The request I am sending is not triggered by a button.

Oh I forgot, I am not getting any errors nor redirects. 

It’s a bit weird, I admit. Especially the fact that the callback is called twice, I don’t know lua nor luasocket good enough to make assumptions on how callback function is stored and handled, but after some investigation I am pretty sure it’s connected to the “issue” on android.

Engineering will need a bug report with code that shows the problem.  Please file a bug report.  The project needs to be complete (main.lua, build.settings, config.lua and any resources needed to run the app.  Put it in a .zip file and use the Report a bug link at the top.

Please post the Case ID # that gets emailed to you back here.

Rob

Rob,

no problem, I will create an issue, but I will also need some support about… how to create it?

the easiest way would be to include in main a single network.request, which in many cases does the job, but we all know in most cases it works fine so… what do I include in order to make this issue meaningful?

Before I send a request, I generate a timestamp with milliseconds and the same timestamp comes to me 2-3 times in a row, so I know I am not imagining things :slight_smile:

Thanks

Krystian

I would just note that you may have to try it several times to get it to fail.  Perhaps ad a button that triggers the network request so the engineer can just tap it repeatedly until he can see the issue.

Rob

You might want to setup an alternate script/web page that doesn’t catch the error, or responds back something to indicate that it’s happening multiple times. This may be the tricky part, is showing them it’s happening.

Rob

I’m very interested to see what this is caused by… I’m about to release an app that relies a lot of its functionality on a php based REST API… though I never experienced this issue myself, it would be pretty bad if it started happening just as I release the app.

krystian, can you in the meantime at least post some specifics of what you’re testing the app on? i am testing on a couple of samsung, HTC and Sony devices and never ran into the issue yet…

Right,

I’ll get back to it on monday.

I need to find something that would throttle the internet connection so that this is possible to reproduce it.

K