What's the ideal AgentX++ subagent loop?

Hi,

I am investigating unexplained timeouts, and other odd behaviour (i.e. snmpset randomly failing immediately with ENOCREATION) (I am using UNIX sockets)

Both our master agent and subagent processing loops are the same:

      while (agent_running && (!mib->get_agentx()->quit()))
      {
         Agentpp::Request *req = reqList->receive(1);
         if (req)
         {
            mib->process_request(req);
         }
         else if ((reqList->size() == 0) &&
               (mib->get_thread_pool()->is_idle()))
         {
            mib->cleanup();
         }
      }

Looking at the example master.cpp, subagent.cpp and subagent2.cpp in AgentX++2.6.1 there are some notable differences:

  • the reqList->receive() timeouts are 20000 for subagent1, 40000 for subagent 2, but only 2 for master
  • subagent2 calls reqList->terminate_set_requests()
  • subagent1 uses ping_master() but subagent2 does not
  • mib->cleanup() logic is only done by the master and subagent2.

What would be really useful, is the golden example of master and subagent loops.

Thanks in advance

Steve

I am afraid, that there is no “golden” way to construct the main loop, because that depends on what the agent needs to do besides answering SNMP or AgentX requests.

The construction of the main loop is only the source of blocked requests, if there is code that locks Mib objects. Otherwise, increasing the thread pool size or trying the request objects always in lexicographic order of their OIDs helps to avoid deadlocks.

The new releases of SNMP++ (4.0.0) and AGENT++ (5.0.0) have some fixes about deadlocks that may occur if locking is not done in proper order and a fix about a race condition, that reads freed data if logging is enabled.