@Test public void testPrematureShutdown() throws InterruptedException { //The error doesn't always happen right away since the order of operations can vary based on thread scheduling //but it happens for me by iteration 25 in most cases for(int i = 0; i < 100000; i++) { final BasicClientConnectionManager mgr = createConnManager(null); final HttpHost target = getServerHttp(); final HttpRoute route = new HttpRoute(target, null, false); final ManagedClientConnection conn = mgr.getConnection(route, null); mgr.releaseConnection(conn, 100, TimeUnit.MILLISECONDS); final class ShutdownRunnable implements Runnable { public void run() { try { mgr.shutdown(); } catch (final Exception e) { throw new RuntimeException(e); } } } //The problem is more reproducible if we slow down the threads below that synchronize on mgr //The problem should occur when shutdown and releaseConnection (or any other method guarded by assertNotShutdown) //is called final class LockTheManager implements Runnable { public void run() { try { synchronized(mgr) { Thread.sleep(1000); //just to slow our synchronized methods } } catch(Exception exc) { } } } try { ManagedClientConnection connReq = mgr.getConnection(route, null); final Thread shutdown = new Thread(new ShutdownRunnable()); final Thread lockout = new Thread(new LockTheManager()); lockout.start(); shutdown.start(); mgr.releaseConnection(connReq, 1000, TimeUnit.MILLISECONDS); } catch(Exception iexc) { if(iexc.getMessage() == null || !iexc.getMessage().equals("Connection manager has been shut down")) { throw new RuntimeException("Failed on iteration: " + i, iexc); } } } }