This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TM4C1294NCPDT: Http server issue

Part Number: TM4C1294NCPDT

Tool/software: TI-RTOS

I am using TI RTOS HTTP server for TM4C1294. I created a web page. When i reload the page 5-6 times. I get the following heap memory allocation error. I allocated sufficient heap memory around 88Kbytes but still getting this issue. It look like the NDK is not de-allocating the heap memory. Can you please help on this issue?

I checked the heap memory through ROV view in IAR and i can see the free memory is very small when this issue occur.

  • Hi Saleem,

    Yes, you are out of heap for sure.

    Could you please tell me more about the following output:

    "NFC Task Started"

    Where is this print located? Is it at the beginning of a Task thread?

    Could you please take a screen shot of the Task view in ROV when this happens? I would like to see the list of Tasks that are active in your app.

    Steve
  • Hi Steve,

    Yes i am getting out of heap. The NFC task is being called periodically. I am 100% sure this issue occurs when i establish connection with HTTP server from web browser. After about 10 time refreshing the webpage, this error occurs(could not allocate memory).

    The other tasks are not causing this issue. The following is the Task view when this issue occurs. I have not shown the NFC task but it is in running mode, it is not doing any functionality except printing the message.

    I have added the watch and monitoring the variables updated on memory allocation and de-allocation(in file mem.c) and here is the output result when this issue occurs. From this we can see the memory is allocated 215 times but freed only 134 times. Which result in less heap memory and then we see the out of memory error.

    I am using the NDK ndk_2_25_00_09 and TI RTOS tirtos_tivac_2_16_01_14. 

    It look like when the client connect with server the memory is allocated each time but not freed.

  • Is the NFC task being created and deleted multiple times?   Or is it persisting throughout the program, with a loop inside it to keep it going?

    The reason I'm asking is because I don't see that Task in your ROV view.  This is implying to me that it is being constantly created/deleted.

    ----

    Can you try adding the Telnet console into your app?  This will allow you to telnet into the TM4C board and get some insight into the stack.

    In particular, you can check the existing sockets in the program.

    You can add the following config code into your app's *.cfg file (using a text editor). Just add this at the end of the file:

    var Telnet = xdc.useModule('ti.ndk.config.Telnet');

    var telnetParams = new Telnet.Params();

    telnetParams.callBackFxn = '&ConsoleOpen';

    var telnet = Telnet.create(telnetParams);

    Due to a known issue, you need to also add this C code into one of your source files.  I usually just put it above the main() function:

    char *VerStr = "\nNDK Telnet Console\n"; // make this a global variable

    Rebuild your app and run it again.  You can telnet from a DOS shell or Linux shell (or similar):

    >telnet <ip addr of your TM4C>

    Once in, you'll see a terminal in which you can run commands ("?" lists commands).  I'm interested in the following:

    >socket tcp


    This should display the TCP sockets that are present in the app.

    Can you try this right when your app starts?  I.e. before you refresh the web page.
      What do you see?

    Then try refreshing the web page.  Then run the socket command again. Are there more sockets in the table?


    And keep going (refreshing).  Do the number of sockets keep increasing?


    Steve

  • Hi Steve,

    The NFC task is created once only. I intentionally not shown the NFC task in the screen shot.

    The sockets kept on increasing on each web page refresh. When ever a page is laoded the sockets are increasing in the table.

    I run the socket command. Here is detail.

    The webpage never open after this and in debugging i can see terminal shows "cannot allocate memory"

    The status of the memory is when the heap goes to out of memory:

    Please suggest some solution for this issue.

  • Hi Saleem,

    Thanks for providing this useful info. I'm looking into this and will get back to you once I know more.

    Steve
  • Saleem,

    I'm having trouble reproducing this issue.  Did you set any special socket options in your app?

    Maybe you could create a simple test case that I can try here locally to see the issue.

    Also, please give the attached modified TivaC example that adds a webpage.  You can connect to this in your browser via the IP address.  There, you will see an option to display the socket table.

    When I refresh the page, I don't see any increase in the list of sockets in the table.

    Can you give it a try and tell me if you see the same problem?

    Steve

    2678.tcpEchoExWithHttpServer.zip

  • Hi Steve,

    Thank you for sending the example. It is very helpful. The example is working fine. But when i enable idle task, then the heap issue start occurring again. I am sending back two files tcpEcho.c and .cfg after adding the idle task. Can you please review or try at your side to see the issue.

    8738.tcpEcho.zip

    Thanks.

    Saleem

  • Hi saleem,


    The TIME_WAITS on target sockets might be do to TTL time setting not existing for TCP de-allocating a Pcb when the http session is closed??

    BTW when tasks are entered in the TASK module an option box (vital) can be checked which might help to end orphaned NDK socket secessions. Web sites use session state bag and http client timeout setting to disconnect orphaned connections. Usually after an hour these days and have seen webmaster set 15 minutes or less with all the hacking going on.

  • Saleem,

    Ok, thanks for posting that. I will give this a try and see if I can reproduce the problem.

    Steve
  • Saleem,

    Were you able to get past this issue?

    Steve

  • Hi Steve,

    It works without idle task. If you can check why it does not work when idle task is enabled. It will be very helpful.

    Thanks.

    Saleem
  • Saleem,

    The Idle module works by running whenever there are no other Task threads running in your system.  When it runs, it sits in an infinite while loop which calls all of the user configured idle functions.  These functions must return.

    I see in your TaskIdle function that you have an infinite loop:

    void TaskIdle(void)
    {    
        while(1)
        {
            //System_printf("In TaskIdle \n");
            //System_flush();
            Task_sleep(5);
        }
    }

    This will cause issues b/c the Idle thread will be stuck in this loop, the first time it calls your idle function.  This will prevent other idle functions from being called by the Idle loop.

    In the NDK, terminated tasks are cleaned up in the idle loop.  This is one of the functions that would be prevented to run by that infinite loop in TaskIdle.

    This may be the reason you are seeing issues with running out of memory.

    Steve

  • Hi Steve,

    We still have issues when running with idle task. If you can check with idle task, it will be very helpful.

    Thanks.

    Saleem
  • Saleem,


    Did you remove the infinite loop in your idle function?

    E.g. I did this:

    void TaskIdle(void)
    {    
        // while(1)
        // {
            //System_printf("In TaskIdle \n");
            //System_flush();
            Task_sleep(5);
        // }
    }

    Steve