confirm bug in network.cancel (only in mac and ios device)

hi.

my app crashes only on mac and ios, i managed to find out where it was crashing and i reproduced the crash with this simple code:

local requestId local function networkListener( event ) if ( event.isError ) then print( "Network error: ", event.response ) else print( "Request complete" ) network.cancel( requestId ) requestId=nil end end local paramsImg = {} paramsImg.bodyType = "binary" paramsImg.response = { filename = "bug.png", baseDirectory = system.TemporaryDirectory, } requestId = network.request( "https://coronalabs.com/wp-content/uploads/2016/02/corona-labs-logo.png", "GET", networkListener, paramsImg )

if i execute the code on windows or android device it will work fine… it will download the image and put ir in temporary directory.

if i try the same on Mac or IOS device will crash when i try to remove the requestId. the image will be created but the removing part will crash the app.

if you comment the lines “network.cancel (requestId) requestId=nil” it will work fine in both devices.

can someone help me try this code in your machine if it will crash? or i’m doing something wrong removing the request. if so why it works on android/windows machines.

regards,

Carlos.

P.S.: tested with build 2016.2886 on Mac OS X El Capitan and Windows 7. devices tested: nexus 7 (android 6.01) and ipad (ios 9.3.2)

If the network request is complete there isn’t a reason to cancel it. The idea behind cancel is to give your users a way to cancel long running requests. This assumes the request is still active.

On Apple OS’s perhaps they are clearing the request for you and you’re trying to cancel something that doesn’t exist. This probably shouldn’t crash, but you don’t need to be cancelling an already cancelled call.

If you can go ahead and file a bug report on it, that would be great so we can stop network.cancel() from crashing, but you can easily work around it.

Rob

thx for the reply rob, i will submit a bug report.

in my case is not that simple like you are saying. i simplifed the code so people could check if it crash or not in their device/computer.

all my network.requests are putted in a table.

i’ve a generic function to remove network requests, only have 1 parameter, a table of requests.

it will cancel all requests from that table and put them to nil. this function is usefull to remove all the handlers not only when they are finished but most important, while they are in the middle, when someone hits the back button, or move from one scene to another while the requests are happening, but the function is the same, so i never know if the requests are finished or not. some will be, but some could not be…or maybe all. i could remove them from the table after the end of each request, but i really think this is not the way to go. network.request() returns an handler, canceling that handler after its completed should be doing nothing, not crashing the app :slight_smile: thanks again, rob.

Regards, Carlos.

Is there a reason you can’t just nil out the table entry when you get a completed event?

Rob

Hi Carlos, as Rob pointed,there is no reason to cancel the request if it is complete.

I removed the following lines :

network.cancel( requestId ) requestId=nil 

And it works on Mac OS X.

However, when I build with a Mac OS X production profile it does not work.

Here is my build settings :

settings = { iphone = { plist = { NSAppTransportSecurity = { NSAllowsArbitraryLoads = true }, }, }, osx = { plist = { NSAppTransportSecurity = { NSAllowsArbitraryLoads = true }, }, }, orientation = { default = "landscapeRight", supported = { "landscapeLeft", "landscapeRight", }, }, window = { defaultMode = "normal", enableCloseButton = true, enableMaximizeButton = true, enableMinimizeButton = true, suspendWhenMinimized = true, resizable = true, titleText = { default = "Check Network" }, }, }

Can you check if it works on your side ?

@Lourenco, i know if i remove those lines the app will work. my real life code is nothing like the one i’m posting here. this is an example, to show how to crash the app. i tried to explain that in my second post, guess my poor english don’t let me explain it better.

what doesnt work in your app with Mac OS X production profile?

@rob, i tried to explain in my second post. but no, i can’t just nil out when is completed because when i call my generic remove function it doesn’t know if the network requests table is completed or not, it’s a generic function that only accepts tables as parameters.

i use the same method in transitions/timers and it works fine, only network requests crashes the app.

Have you filed a bug report?

Do you have the CaseID number that was emailed to you?

case 46145.

In my testing the crash only occurs if I call network.cancel() in the “ended” phase of the network listener.  I can cancel active and completed requests anywhere else without issue.  This explains why everyone isn’t complaining that network.cancel() is broken :slight_smile:

Obviously we shouldn’t crash under any circumstances and I’m tracking down the bug and will fix it but in the meantime you should be able to carry on by making sure not to call network.cancel() from the “ended” phase … if your real code isn’t doing that then please submit an updated reproducible case as that’s the only case that crashes for me.

The issue with the crash when network.cancel() is called for a request in it’s own “ended” phase should be fixed in Daily Build CoronaSDK 2016.2889

If this doesn’t fix it for you, please submit a new reproducible case as I can’t make it crash any other way.

thanks Perry, i can confirm that the bug is not there anymore.

If the network request is complete there isn’t a reason to cancel it. The idea behind cancel is to give your users a way to cancel long running requests. This assumes the request is still active.

On Apple OS’s perhaps they are clearing the request for you and you’re trying to cancel something that doesn’t exist. This probably shouldn’t crash, but you don’t need to be cancelling an already cancelled call.

If you can go ahead and file a bug report on it, that would be great so we can stop network.cancel() from crashing, but you can easily work around it.

Rob

thx for the reply rob, i will submit a bug report.

in my case is not that simple like you are saying. i simplifed the code so people could check if it crash or not in their device/computer.

all my network.requests are putted in a table.

i’ve a generic function to remove network requests, only have 1 parameter, a table of requests.

it will cancel all requests from that table and put them to nil. this function is usefull to remove all the handlers not only when they are finished but most important, while they are in the middle, when someone hits the back button, or move from one scene to another while the requests are happening, but the function is the same, so i never know if the requests are finished or not. some will be, but some could not be…or maybe all. i could remove them from the table after the end of each request, but i really think this is not the way to go. network.request() returns an handler, canceling that handler after its completed should be doing nothing, not crashing the app :slight_smile: thanks again, rob.

Regards, Carlos.

Is there a reason you can’t just nil out the table entry when you get a completed event?

Rob

Hi Carlos, as Rob pointed,there is no reason to cancel the request if it is complete.

I removed the following lines :

network.cancel( requestId ) requestId=nil 

And it works on Mac OS X.

However, when I build with a Mac OS X production profile it does not work.

Here is my build settings :

settings = { iphone = { plist = { NSAppTransportSecurity = { NSAllowsArbitraryLoads = true }, }, }, osx = { plist = { NSAppTransportSecurity = { NSAllowsArbitraryLoads = true }, }, }, orientation = { default = "landscapeRight", supported = { "landscapeLeft", "landscapeRight", }, }, window = { defaultMode = "normal", enableCloseButton = true, enableMaximizeButton = true, enableMinimizeButton = true, suspendWhenMinimized = true, resizable = true, titleText = { default = "Check Network" }, }, }

Can you check if it works on your side ?

@Lourenco, i know if i remove those lines the app will work. my real life code is nothing like the one i’m posting here. this is an example, to show how to crash the app. i tried to explain that in my second post, guess my poor english don’t let me explain it better.

what doesnt work in your app with Mac OS X production profile?

@rob, i tried to explain in my second post. but no, i can’t just nil out when is completed because when i call my generic remove function it doesn’t know if the network requests table is completed or not, it’s a generic function that only accepts tables as parameters.

i use the same method in transitions/timers and it works fine, only network requests crashes the app.

Have you filed a bug report?

Do you have the CaseID number that was emailed to you?

case 46145.

In my testing the crash only occurs if I call network.cancel() in the “ended” phase of the network listener.  I can cancel active and completed requests anywhere else without issue.  This explains why everyone isn’t complaining that network.cancel() is broken :slight_smile:

Obviously we shouldn’t crash under any circumstances and I’m tracking down the bug and will fix it but in the meantime you should be able to carry on by making sure not to call network.cancel() from the “ended” phase … if your real code isn’t doing that then please submit an updated reproducible case as that’s the only case that crashes for me.

The issue with the crash when network.cancel() is called for a request in it’s own “ended” phase should be fixed in Daily Build CoronaSDK 2016.2889

If this doesn’t fix it for you, please submit a new reproducible case as I can’t make it crash any other way.