makeWebRequest error -403 despite enough free memory

Guys, please help on this one:

after several days working, my wf started to return an -403 error upon makeWebRequest.

right after makeWebRequest my free memory is: 11544

header says: content-length: 1697\r\n

at the begining of onWebResponse: 11136

that memory is few coz it's part of the allowed for background process but even so it is waaaay more than needed.

then i reminded i update sdk last night to 4.1.1, but i´ve already returned to 4.0.9 and same behavior occurs.

All i could think is that some models had web response limitation reduced, or the web service had the response increased beyond that limit, if there is any.

anyway i think 1697 (1,6 kB?) is too few.

 Any ideas? 

  • If you are getting json data, you can't really use the number of bytes in the response, as it will be converted into a ciq dictionary, and depending on how complex the data is, that will be far more than 1700 bytes.  If you're seeing a -403, it ran out of memory doing this conversion.

    It could be it stopped working because the service returns a larger response under some conditions.

    Try doing the same makeWebrequest in the foreground in a widget or device app to get a better handle on the actual memory involved.

  • i got you mate. the answer is the same in both calls. before investing on an test app/widget, i refined memory analisys, so now maybe we can sort things out. 

    more precise info:

    right after request i had: 12208
    right after response: 4592

    that is so much data, but it got handled ok.

    the problem is that i run another request similar on the same bg run.

    for that to work i need that data, which i already processed, get deleted.

    but the 2nd request is running already without room.

    how can i free data of first request before doing second one? it seems data = null; was not enough ),:
    EDIT: guess my problem is that i am calling makeWebRequest from within onWebResponse, and thus POSSIBLY nesting calls.

  • Are you using a global to store your data?

  • i use a local in the lifetime of background process, so in every onWebResponse read the json data to it.
    after last request/response i background.exit this local.
    the villain here is still the json data parameter of onWebResponse. if i could ensure memory were rid of it before next response would be problem solved.

  • in case others are troubled with this. guess i finally found a ninja workaround:


    INSTEAD OF:

    function onWebResponse(responseCode, data) {//BIG data
    ...
    //nested real request may stack another BIG data
    Communications.makeWebRequest(url, params, options, self.method(:onWebResponse));
    ...
    }



    TRY THIS:

    function onWebResponse(responseCode, data) { //BIG data
    ...
    //dummy call to ensure leaving method
    return Communications.makeWebRequest("", {}, {}, self.method(:onDummyResponse)); 
    ...
    }
    function onDummyResponse(responseCode, data) {//no data at all
        //real call after onWebResponse scoped out
        return Communications.makeWebRequest(url, params, options, self.method(:onWebResponse));
    }