AsyncHttpClient/async-http-client — pull request #488 by tootedom (2014-02-23 11:03:51+00:00)
Title: Semaphore (in connection tracking) permit leak when host is not contactable

Hi there,

This is a potential fix for en edge that causes permits to leak from the semaphore in the NettyAsyncHttpProvider, when connections are being tracked.

The issue occurs where the host is not contactable. When the connection to the host is attempted, the future is completed before it is added to closed channel group (when using blocking connections). As a result the permit associated with that attempted connection is leaked (as it is not freed). This edge case is much more evident when using a blocking connect attempt, but can occur for Async connection is enabled (NettyAsyncHttpProviderConfig.EXECUTE_ASYNC_CONNECT,true) where c.future.isCancelled() || c.future.isDone() are true

I've provided a test case to replicate the issue, and provided a the potential fix for the leak.

cheers
/dom