CPU hog in AgentX++ 2.6.0

Hi, I have on occasion seen my SNMP Master AgentX agent appear to get stuck in a tight-loop, and not responding to requests. top shows processor load nearing 100%

The gdb backtrace is below. OS details are:

Linux 4.19.317-cip111-rt37 #1 SMP PREEMPT RT Wed Apr 15 18:44:42 BST 2026 x86_64 GNU/Linux

#0  0x00007fe208781757 in Agentpp::MasterAgentXMib::send_pending_ax(unsigned long) () from /opt/Platform/ThirdParty/lib/libagentx++.so.26
(gdb) bt
#0  0x00007fe208781757 in Agentpp::MasterAgentXMib::send_pending_ax(unsigned long) () from /opt/Platform/ThirdParty/lib/libagentx++.so.26
#1  0x00007fe208781b1e in Agentpp::MasterAgentXMib::finalize(Agentpp::Request*) () from /opt/Platform/ThirdParty/lib/libagentx++.so.26
#2  0x00007fe208a72de4 in Agentpp::Mib::do_process_request(Agentpp::Request*) () from /opt/Platform/ThirdParty/lib/libagent++.so.47
#3  0x00007fe208788529 in Agentpp::MasterAgentXMib::process_ax_set_response(Agentpp::AgentXPdu&, Agentpp::AgentXPdu const&, int*, Agentpp::Request*) () from /opt/Platform/ThirdParty/lib/libagentx++.so.26
#4  0x00007fe208787bb2 in Agentpp::MasterAgentXMib::process_ax_response(Agentpp::AgentXPdu&, bool) ()
   from /opt/Platform/ThirdParty/lib/libagentx++.so.26
#5  0x00007fe20877e22a in Agentpp::AgentXResponseTask::run() () from /opt/Platform/ThirdParty/lib/libagentx++.so.26
#6  0x00007fe208aa9210 in Agentpp::TaskManager::run() () from /opt/Platform/ThirdParty/lib/libagent++.so.47
#7  0x00007fe208aa853f in Agentpp::thread_starter(void*) () from /opt/Platform/ThirdParty/lib/libagent++.so.47
#8  0x00007fe209340bc7 in start_thread () from /usr/lib/libpthread.so.0
#9  0x00007fe209076c6f in clone () from /usr/lib/libc.so.6

Ok, I am going to check it today.

1 Like

This is indeed a bug. There is the possibility of an infinite loop when the subagent connection is gone while a SET request is processed in the master.

The following change between // Session gone and the next continue; fixes the issue:

bool MasterAgentXMib::send_pending_ax(unsigned long tid)
{
	int count = 0;
	agentx->lock_queue();
	
	LOG_BEGIN(loggerModuleName, EVENT_LOG | 3);
	LOG("MasterAgentXMib: sending AgentX subrequests (tid)");
	LOG(tid);
	LOG_END;

	OrderedListCursor<AgentXPdu> cur(agentx->get_queue()->elements());
	for (; cur.get(); ) {
		AgentXPdu* pdu = cur.get();
		if ((pdu->get_transaction_id() == tid) &&
		    (pdu->get_timestamp() == 0)) {
			count++;
			// not yet sent
			AgentXSession session;
			if (!openSessions.get_session(pdu->get_session_id(), session)) {
				// Session gone — mark as timed-out so the request expires normally
				time_t t = AgentX::compute_timeout(pdu->get_timeout());
				pdu->set_timestamp(t);
				cur.next();   // must advance, otherwise the loop spins forever
				continue;
			}
			time_t t = AgentX::compute_timeout(pdu->get_timeout());
			pdu->set_timestamp(t);

			agentx->send_agentx(session.get_peer().sd, *pdu);
			// fire off cleanup -> do not wait for response 
			if (pdu->get_agentx_type() == AGENTX_CLEANUPSET_PDU) {
				cur.next();
				agentx->get_queue()->remove(pdu);
				continue;
			}
		}
		cur.next();
	}	
	agentx->unlock_queue();

	LOG_BEGIN(loggerModuleName, EVENT_LOG | 3);
	LOG("MasterAgentXMib: sent AgentX subrequests (tid)(count)");
	LOG(tid);
	LOG(count);
	LOG_END;

	return (count > 0);
} 

AgentX++ 2.6.1 has been released which fixes this issue.

Awesome, thanks Frank !