HTTPASYNC-152: InternalIODispatch#createConnection to throw CancelledKeyException instead of IllegalStateException

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/branches/4.1.x@1865641 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
index fa04c6b..ba4b962 100644
--- a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
+++ b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
@@ -28,6 +28,7 @@
 package org.apache.http.impl.nio.client;
 
 import java.io.IOException;
+import java.nio.channels.CancelledKeyException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -53,7 +54,12 @@
 
     @Override
     protected DefaultNHttpClientConnection createConnection(final IOSession session) {
-        throw new IllegalStateException("Connection must be created by connection manager");
+        // This method should never get called under normal circumstances
+        // Connection object should be created by the connection manager
+        // upon completion of the session request
+        log.debug("Unexpected invocation of #createConnection");
+        session.close();
+        throw new CancelledKeyException();
     }
 
     @Override