networ.request bug!

please confirm this bug:


– main.lua


– Your code here

local requestId={}

local requestId2={}

local count=1

local count2=2

local function networkListener( event )

    if ( event.isError ) then

        print( "Network error: ", event.response )

    else

        print( “Request complete 1”, count )

count=count+1

    end

end

local function networkListener2( event )

    if ( event.isError ) then

        print( "Network error: ", event.response )

    else

        print( “Request complete 2”, count2 )

count2=count2+1

    end

end

local paramsImg = {}

paramsImg.bodyType = “binary”

paramsImg.response = {

filename = “bug.png”,

baseDirectory = system.TemporaryDirectory,

}

local paramsImg2 = {}

paramsImg.bodyType = “binary”

paramsImg.response = {

filename = “bug2.png”,

baseDirectory = system.TemporaryDirectory,

}

for i=1, 50 do

requestId[i] = network.request( “https://coronalabs.com/wp-content/uploads/2016/02/corona-labs-logo.png”, “GET”, networkListener, paramsImg )

end

local function removePedido()

print (“a cancelar os pedidos do 1 ---------------------------------------------------------------”)

for i=1, 50 do

requestId2[i] = network.request( “https://coronalabs.com/wp-content/uploads/2016/02/corona-labs-logo.png”, “GET”, networkListener2, paramsImg2 )

end

for i=#requestId, 1, -1 do

network.cancel(requestId[i])

requestId[i]=nil

end

end

timer.performWithDelay(500, removePedido, 1)

this is what the console reports:

09:25:59.084  Request complete 1 1

09:25:59.084  Request complete 1 2

09:25:59.084  Request complete 1 3

09:25:59.084  Request complete 1 4

09:25:59.084  Request complete 1 5

09:25:59.084  Request complete 1 6

09:25:59.084  Request complete 1 7

09:25:59.099  Request complete 1 8

09:25:59.099  Request complete 1 9

09:25:59.099  Request complete 1 10

09:25:59.099  Request complete 1 11

09:25:59.099  Request complete 1 12

09:25:59.099  Request complete 1 13

09:25:59.099  Request complete 1 14

09:25:59.115  Request complete 1 15

09:25:59.115  Request complete 1 16

09:25:59.115  Request complete 1 17

09:25:59.115  Request complete 1 18

09:25:59.115  Request complete 1 19

09:25:59.115  Request complete 1 20

09:25:59.115  Request complete 1 21

09:25:59.115  Request complete 1 22

09:25:59.130  Request complete 1 23

09:25:59.130  Request complete 1 24

09:25:59.130  Request complete 1 25

09:25:59.130  Request complete 1 26

09:25:59.130  Request complete 1 27

09:25:59.130  Request complete 1 28

09:25:59.130  Request complete 1 29

09:25:59.130  Request complete 1 30

09:25:59.146  Request complete 1 31

09:25:59.146  Request complete 1 32

09:25:59.146  Request complete 1 33

09:25:59.146  Request complete 1 34

09:25:59.146  Request complete 1 35

09:25:59.146  Request complete 1 36

09:25:59.318  Request complete 1 37

09:25:59.318  Request complete 1 38

09:25:59.318  Request complete 1 39

09:25:59.443  Request complete 1 40

09:25:59.443  Request complete 1 41

09:25:59.459  a cancelar os pedidos do 1 ---------------------------------------------------------------

09:25:59.990  Request complete 2 2

09:25:59.990  Request complete 2 3

09:25:59.990  Request complete 2 4

09:25:59.990  Request complete 2 5

09:25:59.990  Request complete 2 6

09:25:59.990  Request complete 2 7

09:25:59.990  Request complete 2 8

09:25:59.990  Request complete 2 9

09:25:59.990  Request complete 2 10

i’ve made this code just for testing propose my real code is 100x times different and complicated so i can’t put it here, but the idea is the same.

the idea is, imagine a tableview that is downloading some pictures, but pressed a button to change scene to do a different task, i cancel all requests from the internet from that scene, i don’t need them anymore because i’m changing to a different scene. in the new scene i do new requests to the internet also. to pass from 1 scene to another i make a fade effect from one to the other, so both exists at the same time for a brief period of time, what i notice when both exist, if i cancel the requests from the first scene, the requests from the second are also canceled, they are in different tables and different variables, network.cancel(object) is not removing only the object its supposed.

resume:

if i have 2 different requests to the internet at the same time, if i cancel the first one, the second will be canceled also, only if the requests from the first one where alread completed. 

i’ve put this code to check that. please someone confirm it. please note that i can only replicate this problem on windows machine, on the mac i could not reproduce this problem, in fact in mac i could not cancel any of the requests from table “requestId”, only when timer was set to 0.

regards,

Carlos.

Try having your cancel loop count down instead of up. When using # to get the length and you start nilling out entries at the beginning, it can do weird things:

for i = #yourTable, 1, -1 do

Next, I would separate the cancel loop from your new fetch loop. I would cancel as soon as you know you’re going to the new scene and not start up the new fetch loop until you’re into the next scene.

Rob

rob thanks for the reply.

i’m already canceling count down,

for i=#requestId, 1, -1 do network.cancel(requestId[i]) requestId[i]=nil end

i know i resolve the problem if i cancel first then create a new scene, in fact is what i’m using right now till the problem is solved. but i want a fade transition for that i’ve the 2 scenes same time, and i can only delete the first after the top is alpha=1, so both will have network requests same time. i’ve a generic code that make scene transitions and stop all transitions, timers, tableviews, scrollviews, and after delete them all if they exist of a complete scene. i can separte the code, but the bug is still there, if you study carefull the code you notice that it should be IMPOSSIBLE to cancel a network.request from another variable, if i network.cancel(a) it should stop (a) not (b) and that is whats happening. 

When changing scenes I think the ‘code’ portion is still alive regardless of graphical changes unless its specifically set to handle unloading of the scene code on scene change (I could be totally wrong).

Best bet is to do your canceling on leaving the scene. And starting up again when new scene is created.

You may be able to handle it more elegantly by using an external module to manage your process.

~

cbreeze, i know if i cancel all the requests from scene 1 first then go to scene 2 it will work, the problem still remains and its not about scene transition, but about having 2 networks requests same time, and is not about scenes transition.

if i have 2 requests same time and i cancel the first, the second will be canceled that should be impossible since they are different variables. and again i can only reproduce this problem on windows machine, so it looks more a bug. i will report it anyway since noone here explain me better. thanks for the help.

I agree, if its working fine for other platforms I would guess it to be a bug.

I’ll run a test on my Windows box a little later as well. I work with the network stuff a lot so I might be able to spot something.

Sure you know the drill: https://developer.coronalabs.com/content/bug-submission

~

Try having your cancel loop count down instead of up. When using # to get the length and you start nilling out entries at the beginning, it can do weird things:

for i = #yourTable, 1, -1 do

Next, I would separate the cancel loop from your new fetch loop. I would cancel as soon as you know you’re going to the new scene and not start up the new fetch loop until you’re into the next scene.

Rob

rob thanks for the reply.

i’m already canceling count down,

for i=#requestId, 1, -1 do network.cancel(requestId[i]) requestId[i]=nil end

i know i resolve the problem if i cancel first then create a new scene, in fact is what i’m using right now till the problem is solved. but i want a fade transition for that i’ve the 2 scenes same time, and i can only delete the first after the top is alpha=1, so both will have network requests same time. i’ve a generic code that make scene transitions and stop all transitions, timers, tableviews, scrollviews, and after delete them all if they exist of a complete scene. i can separte the code, but the bug is still there, if you study carefull the code you notice that it should be IMPOSSIBLE to cancel a network.request from another variable, if i network.cancel(a) it should stop (a) not (b) and that is whats happening. 

When changing scenes I think the ‘code’ portion is still alive regardless of graphical changes unless its specifically set to handle unloading of the scene code on scene change (I could be totally wrong).

Best bet is to do your canceling on leaving the scene. And starting up again when new scene is created.

You may be able to handle it more elegantly by using an external module to manage your process.

~

cbreeze, i know if i cancel all the requests from scene 1 first then go to scene 2 it will work, the problem still remains and its not about scene transition, but about having 2 networks requests same time, and is not about scenes transition.

if i have 2 requests same time and i cancel the first, the second will be canceled that should be impossible since they are different variables. and again i can only reproduce this problem on windows machine, so it looks more a bug. i will report it anyway since noone here explain me better. thanks for the help.

I agree, if its working fine for other platforms I would guess it to be a bug.

I’ll run a test on my Windows box a little later as well. I work with the network stuff a lot so I might be able to spot something.

Sure you know the drill: https://developer.coronalabs.com/content/bug-submission

~