[AGENT++] Patch to fix Mib::cleanup() and prevent possible deadlock

Claus Klein claus.klein at arcormail.de
Tue Dec 16 23:56:59 CET 2014


Hi Frank,

I have all this done:

void init_signals()
{
	signal(SIGTERM, sig);
	signal(SIGINT, sig);
	signal(SIGSEGV, sig);
	// catch SIGPIPE and ignore it this can occur when the subagent dies when
	// we are trying to response a request after timeout
#ifndef WIN32
	signal(SIGPIPE, SIG_IGN);
#endif
}

The main loop looks like this:

	Request* req;
	do {
		retries = 0;
		while ((continueWork) && (!mib->get_agentx()->quit())) {

			req = reqList->receive(20000);	// ms

			if (req) {
				mib->process_request(req);
			} else {
				mib->ping_master();


				//NOTE possible deadlock at cleanup() -> lock_mib() after get request timeout with Mib::process_request() -> lock_mib()!
				//FIXME reqList->timeout_set_requests();	// does only help for set request timeout!
				mib->cleanup();

				// here we add or remove rows at shared ifTable
				test_index_allocation();
			}
		}

		// Make sure that all pending set requests which may
		// have locked any resources are terminated and resources
		// are freed before connection to master is reestablished.
		reqList->terminate_set_requests();

		//NOTE this calls may end in a deadlock after row destroy timeout or set request timeout! ck
		mib->cleanup();
		mib->save_all();

		while ((continueWork) && (retries++ < 10) && (!mib->init())) {
			Thread::sleep(retries * 1000);    // ms (up to 10 sec)
		}
	} while ((continueWork) && (retries < 10));

Its my modified subagent example code!
If this is wrong, what is the right way to handle this?

Best regards,
Claus

On 16.12.2014, at 23:29, Frank Fock <fock at agentpp.com> wrote:

> Hi Claus,
> 
> The root question to answer is: Why is the thread that runs through the MibEntry::update(..) method
> is terminated without unlocking its locks?
> I would expect the SIGPIPE handler to ignore the signal and set a flag for the main-loop to reconnect
> with the master. The reconnection (and terminate_set_requests) must then not be started before the
> requestList of the sub-agent runs empty.
> 
> Best regards,
> Frank



More information about the AGENTPP mailing list