[omniORB] assert failure during thread creation

Carlson, Andy andycarlson@ipo.att.com
Thu, 7 Oct 1999 03:28:42 -0700


Hi,

I am testing some code based on the omniORB 2.7.1 source under
heavy concurrent load. The following problem happens when resources
are being exhausted, but could be handled more gracefully.

Here is the code (from tcpSocketRendezvouser::run_undetached)...

{
	// locking & state check stuff omitted

	newSt = new tcpSocketStrand(r,new_sock,1);
	newSt->incrRefCount(1);
}

// logging stuff omitted

try {
	newthr = new tcpSocketWorker(newSt);
}
catch(...) {
	newthr = 0;
}

if (!newthr) {
	// big comment omitted
	newSt->decrRefCount();
	newSt->shutdown();
}

The problem is that I sometimes get an assertion failure from
the newSt->decrRefCount() call. This checks that the refcount
doesnt go negative after being decremented.

I think that the problem is this... The tcpSocketWorker is created
and decrements the strand refcount in its constructor. It then calls
start() to start the thread. This (I think) is throwing an exception
which is caught by tcpSocketRendezvouser::run_undetached.

As newthr hasnt been set, the 'if (!newthr) code is run, which 
calls decrRefCount again which dies because the refcount was
already zero.

Suggested fix: prefix the decrRefCount with if (!newSt->is_idle())

Andy
----------------------------------------------------------------------------
-----------
Andy Carlson. AT&T Labs (UK)   	Tel: +44 1527 495258
E-Mail: andycarlson@ipo.att.com	Fax: +44 1527 495229