OK, so I brought this problem upon myself.

There is one executeMethod() call in one of our applications for which we "forgot" to call releaseConnection() or consume the entire response (and I of all people should know better). While I fully realize this is a bug in my code, the failure, unfortunately, is not just an exception thrown, but a deadlock in HttpClient.

What happens, roughly, is this:
Execute a method, forget to releaseConnection(). Do this three times from the AWT event thread, using MultiThreadedHttpConnectionManager(), with a timeout of zero. On the third (or fourth?) time, the application "hangs", with two key threads waiting - one at


MultiThreadedHttpConnectionManager.doGetConnection() - line 302, which reads "connectionPool.wait(timeToWait)",

and the other thread at

MultiThreadedHttpConnectionManager.ReferenceQueuedThread.run(), line 665, which reads "Reference ref = referenceQueue.remove();".

I think invoking HttpClient from the AWT event thread is key, as it prevents further interaction by the user with the application, and thus the garbage collector never gets invoked. Based on this theory, it turns out that I can work around the bug in my code by putting in a call to System.gc() immediately before "connectionPool.wait(timeToWait)". Granted, this doesn't fix the problem in my application's code, but it does potentially solve a serious issue for naive (or careless) users of HttpClient.

This leads me to ask two questions:
Should we add a call to System.gc() at line 302 of MultiThreadedHttpConnectionManager?
Should we ever invoke the "connectionPool.wait()" with a zero value, or should this always time out? I think this would be better if it always timed out, as it is possible, as my scenario shows, to get into states where the garbage collector never runs, the connections are never freed, and the application grinds to a halt.


Mind you, I can live with doing neither of the above changes, and just fixing the *!$%?#!* bug in my application, but I think the changes might make sense.

- With egg on my face - Eric.




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to