Uploaded image for project: 'Near Realtime RAN Intelligent Controller'
  1. Near Realtime RAN Intelligent Controller
  2. RIC-1014

potential race condition in the `listener` function due to multiple `listener` threads.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Medium Medium
    • J
    • None
    • e2
    • None

      In the code the number of CPUs is hard coded to 3. And listener function is started in each of these threads which takes a pointer sctp_params.

          num_cpus = 3;
          std::vector<std::thread> threads(num_cpus);
          for (unsigned int i = 0; i < num_cpus; i++) {
              threads[i] = std::thread(listener, &sctpParams);
      
              cpu_set_t cpuset;
              CPU_ZERO(&cpuset);
              CPU_SET(i, &cpuset);
              int rc = pthread_setaffinity_np(threads[i].native_handle(), sizeof(cpu_set_t), &cpuset);
              if (rc != 0) {
                  mdclog_write(MDCLOG_ERR, "Error calling pthread_setaffinity_np: %d", rc);
              }
          }
      

      There are parts of listener function that can get called from multiple threads without proper lock/protection.

      For example in each of the threads following code could get called simultaneously

      void listener(sctp_params_t *params) {
                  ...
                  } else if (params->rmrListenFd == events[i].data.fd) {
                      // got message from XAPP
                      //num_of_XAPP_messages.fetch_add(1, std::memory_order_release);
                      num_of_messages.fetch_add(1, std::memory_order_release);
                      if (mdclog_level_get() >= MDCLOG_DEBUG) {
                          mdclog_write(MDCLOG_DEBUG, "new RMR message");
                      }
                      if (receiveXappMessages(params->sctpMap,
                                              rmrMessageBuffer,
                                              message.message.time) != 0) {
                          mdclog_write(MDCLOG_ERR, "Error handling Xapp message");
                      }
                  } else if (params->inotifyFD == events[i].data.fd) {
      
            ...
      }
      

      This is a potential race condition.receiveXappMessage takes as input unprotected members from sctp_params. Most likely so far we have not observed this is mainly because if the code runs on a single CPU, this problem won't be observed. Also, we are already using epoll_ctl to handle multiple events so it is suffice to call this function in a single thread. We should be only running a single listener with epoll.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            aditverm Aditya Verma
            gabhijit Abhijit Gadgil
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours
                2h