Traffic Server
  1. Traffic Server
  2. TS-640

Repeated INKInit() / INKTerminate() will leak lots of memory

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1.6
    • Component/s: Management API
    • Labels:
      None

      Description

      If you do

      INKInit();
      INKTerminate()

      repeatedly, the process will leak memory something fiercely.

        Issue Links

          Activity

          Hide
          Yunkai Zhang added a comment -

          Since this issue is closed, I'll append the patch in TS-2141.

          Show
          Yunkai Zhang added a comment - Since this issue is closed, I'll append the patch in TS-2141 .
          Hide
          Yunkai Zhang added a comment -

          Sorry, I use valgrind instead of eyes to test it again, there is no obvious memory leak.

          At least, when remove "TS_MGMT_OPT_NO_SOCK_TESTS" option (traffic_cop need socket_test_thread to reconnect manager), there is no memory leak(after fixed a small bug in Terminate()):

          ==test code==

          int
          main(int argc, char *argv[])
          { 
            int nr_loop = 1000000;
          
            if (argc > 1)
              nr_loop = atoi(argv[1]);
          
            for (int i = 0; i < nr_loop; i++) {
              TSInit("/var/run/trafficserver", static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS));
              sleep(1);
              TSTerminate();
            }
          }
          

          ==valgrind output===

          ....
          ==64760== LEAK SUMMARY:
          ==64760==    definitely lost: 0 bytes in 0 blocks
          ==64760==    indirectly lost: 0 bytes in 0 blocks
          ==64760==      possibly lost: 0 bytes in 0 blocks
          ==64760==    still reachable: 64 bytes in 2 blocks
          ==64760==         suppressed: 0 bytes in 0 blocks
          ==64760==
          ==64760== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)
          --64760--
          --64760-- used_suppression:      6 dl-hack3-cond-1
          ==64760==
          ==64760== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)
          

          So I'll give a patch to remove "TS_MGMT_OPT_NO_SOCK_TESTS" in traffic_cop program and fix a small bug in Terminate().

          Show
          Yunkai Zhang added a comment - Sorry, I use valgrind instead of eyes to test it again, there is no obvious memory leak. At least, when remove "TS_MGMT_OPT_NO_SOCK_TESTS" option (traffic_cop need socket_test_thread to reconnect manager), there is no memory leak(after fixed a small bug in Terminate()): ==test code== int main( int argc, char *argv[]) { int nr_loop = 1000000; if (argc > 1) nr_loop = atoi(argv[1]); for ( int i = 0; i < nr_loop; i++) { TSInit( "/ var /run/trafficserver" , static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS)); sleep(1); TSTerminate(); } } ==valgrind output=== .... ==64760== LEAK SUMMARY: ==64760== definitely lost: 0 bytes in 0 blocks ==64760== indirectly lost: 0 bytes in 0 blocks ==64760== possibly lost: 0 bytes in 0 blocks ==64760== still reachable: 64 bytes in 2 blocks ==64760== suppressed: 0 bytes in 0 blocks ==64760== ==64760== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6) --64760-- --64760-- used_suppression: 6 dl-hack3-cond-1 ==64760== ==64760== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6) So I'll give a patch to remove "TS_MGMT_OPT_NO_SOCK_TESTS" in traffic_cop program and fix a small bug in Terminate().
          Hide
          Yunkai Zhang added a comment -

          In my testing, we didn't fix this bug. There are memory leak when call TsInit() without option in a loop:

          int
          main(int argc, char *argv[])
          { 
            while (true) {
              TSInit("/var/run/trafficserver", static_cast<TSInitOptionT>(0));
              TSTerminate();
              sleep(1);
            }
          }
          

          When I analyzing TS-2141 issue, I found that before applied this commit: ba95f9c6e8c49f69f018885f255db02f31d7335f , traffic_cop would reconnect to traffic_manager automatically by socket_test_thread thread. But this commit introduce TS_MGMT_OPT_NO_SOCK_TESTS option to disable it.

          Maybe we should fix the root cause of memory leak, rather than disable socket_test_thread simply.

          Let me dig more ...

          Show
          Yunkai Zhang added a comment - In my testing, we didn't fix this bug. There are memory leak when call TsInit() without option in a loop: int main( int argc, char *argv[]) { while ( true ) { TSInit( "/ var /run/trafficserver" , static_cast<TSInitOptionT>(0)); TSTerminate(); sleep(1); } } When I analyzing TS-2141 issue, I found that before applied this commit: ba95f9c6e8c49f69f018885f255db02f31d7335f , traffic_cop would reconnect to traffic_manager automatically by socket_test_thread thread. But this commit introduce TS_MGMT_OPT_NO_SOCK_TESTS option to disable it. Maybe we should fix the root cause of memory leak, rather than disable socket_test_thread simply. Let me dig more ...
          Hide
          Leif Hedstrom added a comment -

          I suspect we fail to "kill" the following thread:

          ink_thread_create(event_poll_thread_main, &event_socket_fd);

          I think we should make INKInit() take an optional argument, to let the system know if we're interested in event callbacks. But even so, we obviously should properly "kill" this thread upon INKTerminate().

          Show
          Leif Hedstrom added a comment - I suspect we fail to "kill" the following thread: ink_thread_create(event_poll_thread_main, &event_socket_fd); I think we should make INKInit() take an optional argument, to let the system know if we're interested in event callbacks. But even so, we obviously should properly "kill" this thread upon INKTerminate().

            People

            • Assignee:
              Leif Hedstrom
              Reporter:
              Leif Hedstrom
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development