cJSON Parse failure / Failed to print JSON object

Hi everyone,

I am using SDK Toolchain v2.3.0 and my code is based on the aws_iot example.  I am getting either "cJSON Parse failure" or "Failed to print JSON object" error if I leave the device running for days.  The device will be stuck with that error and never recover unless I reboot.  The interesting part is that these errors seem to happen with the 1NCE SIM that I am using.  I don't have these error if I use Truphone (now 1Global) SIM.  According to 1NCE, they saw a PDP context is opened for days.  Is this the reason for the cJSON error?  What will be the best way to correct this error?  Thank you.

Parents
  • The best would be to log the data that cJSON fails to parse or print. Probably the data is corrupt in some way. But it is hard to guess without seeing the data.

  • Hi,

    According to 1NCE, they saw a PDP context is opened for days.  Is this the reason for the cJSON error?

    It cannot be ruled out that it is somehow related. E.g., does it lead to larger JSON objects? Does it lead to stack overflow or otherwise memory exhaustion?

    device will be stuck with that error and never recover unless I reboot.

    This might have to do with the application logic. E.g., are you retrying indefinitely to handle the same (faulty) JSON structure? This could be multiple different types of infinite loop, deadlock (or even livelock), or other. Since it happens after a few days, a debug session for investigating the state of the device when this happens might be difficult, but increased logging would be a good plan B.

    Jakob Ruhe said:
    The best would be to log the data that cJSON fails to parse or print. Probably the data is corrupt in some way. But it is hard to guess without seeing the data.

    Having the data definitely could shed some light on what might be the issue. In addition, exact API calls and (error) return values, what is the state of the device when failing, etc. any additional information, really.

    If the root cause is not found, there could still be possible workarounds, e.g. closing the PDP context, or using a watchdog to reset the device, etc.

    Regards,
    Terje

  • Thank you very much for all the inputs.  The occurrence is very difficult to catch.  I have 7 devices running at the same time, 3 with 1NCE SIM and 4 with Truphone SIM.  So far no cJSON error happened to the 4 with Truphone SIM.  For the other 3, 1 had the error after 4 days, 1 had the error after 7 days, 1 had the error after 8 days.  

    I remember having the cJSON error early in the project with iBASIS SIM.  Increasing the heap and stack sizes seems to correct the problem.  Here is what I have right now.

    # Heap and stacks
    CONFIG_MAIN_STACK_SIZE=8192
    CONFIG_HEAP_MEM_POOL_SIZE=49152
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
    CONFIG_AT_MONITOR_HEAP_SIZE=2048

    The cJSON_Delete(root_obj) function doesn't seem to fix the problem.  Yesterday, I put a watchdog reset whenever I see "cJSON Parse failure" or "Failed to print JSON object".  I will let the devices run for another week or so to see what will happen.

    Regards,

    Floyd

  • Hi,

    flau said:
    Increasing the heap and stack sizes seems to correct the problem.

    It may be difficult to know if this just delays the problem, or if it makes it less likely to occur, or if it fixes it entirely. Nevertheless, if you do have more memory left, increasing stack and/or heap further could help also for the current issue.

    flau said:
    reset whenever I see "cJSON Parse failure" or "Failed to print JSON object".

    This is of course also a valid workaround, if it doesn't happen too often.

    I guess if you could also monitor memory usage, then you would see if you somehow got a data buildup or stack buildup.

    Regards,
    Terje

Reply
  • Hi,

    flau said:
    Increasing the heap and stack sizes seems to correct the problem.

    It may be difficult to know if this just delays the problem, or if it makes it less likely to occur, or if it fixes it entirely. Nevertheless, if you do have more memory left, increasing stack and/or heap further could help also for the current issue.

    flau said:
    reset whenever I see "cJSON Parse failure" or "Failed to print JSON object".

    This is of course also a valid workaround, if it doesn't happen too often.

    I guess if you could also monitor memory usage, then you would see if you somehow got a data buildup or stack buildup.

    Regards,
    Terje

Children
No Data
Related