network.request() timeout error

Hi,

When sending a network request to a server that is down, the request timeout in the default 30s or the value set in params.timeout.  Instead of getting a callback to the networklistener, I’m getting this cryptic error message:

<code>

2013-05-25 13:33:01.685 Corona Simulator[81149:f03] -[CoronaURLConnection reportErrors]: unrecognized selector sent to instance 0x108d245c0

2013-05-25 13:33:01.685 Corona Simulator[81149:f03] -[CoronaURLConnection reportErrors]: unrecognized selector sent to instance 0x108d245c0

2013-05-25 13:33:01.687 Corona Simulator[81149:f03] (

    0   CoreFoundation                      0x00007fff9844ef56 __exceptionPreprocess + 198

    1   libobjc.A.dylib                     0x00007fff9448fd5e objc_exception_throw + 43

    2   CoreFoundation                      0x00007fff984db1be -[NSObject doesNotRecognizeSelector:] + 190

    3   CoreFoundation                      0x00007fff9843be23 ___forwarding___ + 371

    4   CoreFoundation                      0x00007fff9843bc38 _CF_forwarding_prep_0 + 232

    5   network.dylib                       0x00000001082a205a -[CoronaConnectionDelegate connection:didFailWithError:] + 206

    6   Foundation                          0x00007fff99939b3b ___NSURLConnectionDidFail_block_invoke_1 + 125

    7   Foundation                          0x00007fff99939ab8 _NSURLConnectionDidFail + 85

    8   CFNetwork                           0x00007fff9972675d _ZN19URLConnectionClient23_clientDidFailWithErrorEP9__CFErrorPNS_26ClientConnectionEventQueueE + 667

    9   CFNetwork                           0x00007fff99725915 _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 885

    10  CFNetwork                           0x00007fff99725aea _ZN19URLConnectionClient26ClientConnectionEventQueue33processAllEventsAndConsumePayloadEP20XConnectionEventInfoI12XClientEvent18XClientEventParamsEl + 1354

    11  CFNetwork                           0x00007fff99650259 _ZN19URLConnectionClient13processEventsEv + 185

    12  CFNetwork                           0x00007fff996500fe _ZN17MultiplexerSource7performEv + 212

    13  CoreFoundation                      0x00007fff983bd4f1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

    14  CoreFoundation                      0x00007fff983bcd5d __CFRunLoopDoSources0 + 253

    15  CoreFoundation                      0x00007fff983e3b49 __CFRunLoopRun + 905

    16  CoreFoundation                      0x00007fff983e3486 CFRunLoopRunSpecific + 230

    17  HIToolbox                           0x00007fff921052bf RunCurrentEventLoopInMode + 277

    18  HIToolbox                           0x00007fff9210c56d ReceiveNextEventCommon + 355

    19  HIToolbox                           0x00007fff9210c3fa BlockUntilNextEventMatchingListInMode + 62

    20  AppKit                              0x00007fff9308f779 _DPSNextEvent + 659

    21  AppKit                              0x00007fff9308f07d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135

    22  AppKit                              0x00007fff9308b9b9 -[NSApplication run] + 470

    23  AppKit                              0x00007fff93307eac NSApplicationMain + 867

    24  Corona Simulator                    0x00000001000023e4 start + 52

    25  ???                                 0x0000000000000003 0x0 + 3

)

</code>

Any idea what this means?  I’m using the lastest daily build.

Thanks.

Nathan.

Are you on a PC or a Mac?

Can you post the code where you’re dealing with your network request?

Hi Rob,

I’m on macosx lion running corona 1127.  The cookieListener doesn’t get called at all when the server suddenly disconnects or is offline.  I get the above error message in both situations.

[lua]

– Grab the cookie for this session

local cookie = ‘’

local function cookieListener( event )

    if ( event.isError ) then

        print( “Network error!”)

    else

        if isDebug then

            print ( "RESPONSE: " … event.response )

        end

        if event.status == 401 then

            print(event.response)

        elseif event.status == 200 then

            if event.responseHeaders[‘Set-Cookie’] then

                cookie = event.responseHeaders[‘Set-Cookie’]

            end

        end        

    end

end

local params = {}

params.timeout = 5

network.request( ‘http://login:password@192.168.1.71:8889’, ‘GET’, cookieListener, params)

[/lua] 

Have the same problem here…any solution? :slight_smile:

its working in corona 996

I put print(event.response) in networkListener, the output “The request timed out.”

but got the same problem with @BoarK using corona 1127

DragonGameStudio,

I reported this bug and it is fixed in the new daily build starting with 1129.

Nathan.

cool! thx BoarK

I still experience this bug - when error happens during request my listener is never called. It happens both for timeout and for unavailable internet connection.

I am using Version 2013.1135 (2013.6.3) for Mac, testing on iPhone4s (with slow Edge internet connection)

Code sample:

local function myListener(event) &nbsp; &nbsp;print("Response: " .. event.response) end function scene:createScene( event ) &nbsp; &nbsp; local group = self.view &nbsp; &nbsp; network.request("https://www.stackmob.com", "GET", myListener, {timeout = 1}) end &nbsp;

Console output of the device (my listener is never called): 

Jun &nbsp;6 16:41:17 ...[10973] \<Warning\>: ERROR: Error during request, code: -1001, details: The request timed out.

Could you fix it?

Are you on a PC or a Mac?

Can you post the code where you’re dealing with your network request?

Hi Rob,

I’m on macosx lion running corona 1127.  The cookieListener doesn’t get called at all when the server suddenly disconnects or is offline.  I get the above error message in both situations.

[lua]

– Grab the cookie for this session

local cookie = ‘’

local function cookieListener( event )

    if ( event.isError ) then

        print( “Network error!”)

    else

        if isDebug then

            print ( "RESPONSE: " … event.response )

        end

        if event.status == 401 then

            print(event.response)

        elseif event.status == 200 then

            if event.responseHeaders[‘Set-Cookie’] then

                cookie = event.responseHeaders[‘Set-Cookie’]

            end

        end        

    end

end

local params = {}

params.timeout = 5

network.request( ‘http://login:password@192.168.1.71:8889’, ‘GET’, cookieListener, params)

[/lua] 

Well I couldn’t quite generate a time out.  But I turned off my WiFi and it fired the event handler.

I would suggest filing a bug report.  Maybe timeouts don’t trigger the event handler.  But not having network does trigger it as expected.

Hi!

I can confirm that timeouts do trigger the event handler both in simulator and on device (ios 5.1) with build 1131. Haven’t tried on any other devices yet. Perhaps this bug is isolated to certain ios / corona versions.

Hmm, let me check it all again, maybe I have messed up somewhere…

I think I finally got it - problem was calling event.response in my listener. This results in runtime error, which is not shown on device but is shown in simulator.

Log output from device:

Jun  7 12:37:39 Se temp[11694] <Warning>: ERROR: Error during request, code: -1001, details: The request timed out.

Jun  7 12:37:39 Se temp[11694] <Warning>: In myListener

Jun  7 12:37:39 Se temp[11694] <Warning>: Event table contents: {

      bytesEstimated = 0,

      bytesTransferred = 0,

      isError = true,

      name = “networkRequest”,

      phase = “ended”,

      requestId = <userdata 1>,

      status = -1,

      url = “http://www.google.com

    }

Thanks for assistance!

Notice that event.response is nil when there is a time out or other error.  When you did the:

print("Response: " … event.response)

using concatenation, it created a run time error because you can’t append a nil to a string.  Had you done this instead:

print("Response: ", event.response)

the print statement is smart enough to not output anything or output “nil” (depending on condition) if it’s a parameter.

You can add the following to config.lua to see the runtime errors on the device (they are off by default).

[lua]

application =
{
    showRuntimeErrors = true,        – set to true to popup errors, defaults to false

{

[/lua]

Thanks a lot guys, your help is invaluable!

Have the same problem here…any solution? :slight_smile:

its working in corona 996

I put print(event.response) in networkListener, the output “The request timed out.”

but got the same problem with @BoarK using corona 1127

DragonGameStudio,

I reported this bug and it is fixed in the new daily build starting with 1129.

Nathan.