hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Burke <jbu...@cs.washington.edu>
Subject @ThreadSafe BasicClientConnectionManager is not threadsafe with respect to shutdown
Date Thu, 30 Aug 2012 19:02:22 GMT

Perhaps it's low priority since the comments of
BasicClientConnectionManager.java does say it ought to be handled by only
one thread but I would like to point out that it is not thread safe with
respect to shutdown in case you're interested.

The attached file includes a test I added to
that will demonstrate a null pointer exception raised by potentially
improper synchronization in BasicClientConnectionManager in relatively
short order.

Since the assignment to variable shutdown in the shutdown method (line 262)
is not part of the synchronize block and none of the assertNotShutdown
method calls are within the synchronized blocks of their enclosing methods,
it is possible to have threads execute the commands of
BasicClientConnectionManager methods in the following sequence.

Thread 1
releaseConnection (or some other method that uses assertNotShutdown is
  assertNotShutdown - Passes - Line 183

Thread 2
  the shutdown flag becomes true - Line 262
  shutdown releases this.poolEntry and this.conn in the synchronized(this)

Thread 1
  release connection's synchronized(this) block get's executed
  this.poolEntry is null in the try block causing a null pointer exception
- Line 211
  this.poolEntry is null in the finally block causing a null pointer
exception - Line 224

Attached is a test case that will generate the attached stack-trace when
added to TestBasicConnManager and a possible fix (though the fix has a cost
of increased synchronization).

Thank you for your time.


View raw message