You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Putul S <sp...@gmail.com> on 2017/04/25 19:40:34 UTC

SolrServerException: Invalid use of BasicClientConnManager: connection still allocated.

Hello,

I am using single instance CloudSolrClient using my HttpClinet. Problem
with using this httpClient is that, whenever I add more than one
document, LBHttpSolrClient complains about connection not released. Everything
works fine is I do not use my own HttpClient.



HttpClient httpClient = new DefaultHttpClient();                     //
also set timeout and authentication parameters

server = new CloudSolrClient("localhost:2198", httpClient);  //singleton
for the app, have tried multi-instance too

CloudSolrClient.add(document);
 //adding document in a loop result sin error


Documents get updated but I end up seeing many Zookeeper connections
established  depending on number of documents added. How do I release
connection when my HttpClient is wrapped within CluodSolrClient? I tried
calling shutting down httpClient connection manager, it did not work.


ERRORS:

org.apache.solr.common.cloud.ConnectionManager] (zkCallback-2-thread-1)
Watcher org.apache.solr.common.cloud.ConnectionManager@29e14ddb
name:ZooKeeperConnection Watcher:localhost.harvard.edu:2181 got event
WatchedEvent

….

org.apache.solr.client.solrj.SolrServerException:
java.lang.IllegalStateException: Invalid use of BasicClientConnManager:
connection still allocated.

Make sure to release the connection before allocating another one.

org.apache.solr.client.solrj.impl.LBHttpSolrClient.doRequest(LBHttpSolrClient.java:410)

org.apache.solr.client.solrj.impl.LBHttpSolrClient.request(LBHttpSolrClient.java:325)


Thank you in advance


Putul

Re: SolrServerException: Invalid use of BasicClientConnManager: connection still allocated.

Posted by sputul <sp...@gmail.com>.
Thank you for the big help!
-- Putul

On Wed, Apr 26, 2017 at 9:22 AM, Shawn Heisey-2 [via Lucene] <
ml+s472066n4331977h61@n3.nabble.com> wrote:

> On 4/25/2017 1:40 PM, Putul S wrote:
> > I am using single instance CloudSolrClient using my HttpClinet.
> > Problem with using this httpClient is that, whenever I add more than
> > one document, LBHttpSolrClient complains about connection not
> > released. Everything works fine is I do not use my own HttpClient.
>
> Apparently the DefaultHttpClient constructor that you used creates a
> client with BasicClientConnManager internally.  This will completely
> break an application that tries to make simultaneous connections with
> multiple threads.  This is the description of BasicClientConnManager in
> its javadoc:
>
> "A connection manager for a single connection. This connection manager
> maintains only one active connection. Even though this class is fully
> thread-safe it ought to be used by one execution thread only, as only
> one thread a time can lease the connection at a time."
>
> Try creating the HttpClient object with its Builder instead.  Here's one
> example:
>
> RequestConfig rc = RequestConfig.custom().setConnectTimeout(5000)
>   .setSocketTimeout(300000).build();
> HttpClient client = HttpClients.custom().setDefaultRequestConfig(rc)
>   .setMaxConnPerRoute(1024).setMaxConnTotal(4096)
>   .disableAutomaticRetries().build();
>
> Thanks,
> Shawn
>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://lucene.472066.n3.nabble.com/SolrServerException-Invalid-
> use-of-BasicClientConnManager-connection-still-allocated-
> tp4331870p4331977.html
> To unsubscribe from SolrServerException: Invalid use of
> BasicClientConnManager: connection still allocated., click here
> <http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4331870&code=c3B1dHVsNThAZ21haWwuY29tfDQzMzE4NzB8MTMxNzYyODE0OQ==>
> .
> NAML
> <http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://lucene.472066.n3.nabble.com/SolrServerException-Invalid-use-of-BasicClientConnManager-connection-still-allocated-tp4331870p4332100.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: SolrServerException: Invalid use of BasicClientConnManager: connection still allocated.

Posted by Shawn Heisey <ap...@elyograg.org>.
On 4/25/2017 1:40 PM, Putul S wrote:
> I am using single instance CloudSolrClient using my HttpClinet.
> Problem with using this httpClient is that, whenever I add more than
> one document, LBHttpSolrClient complains about connection not
> released. Everything works fine is I do not use my own HttpClient.

Apparently the DefaultHttpClient constructor that you used creates a
client with BasicClientConnManager internally.  This will completely
break an application that tries to make simultaneous connections with
multiple threads.  This is the description of BasicClientConnManager in
its javadoc:

"A connection manager for a single connection. This connection manager
maintains only one active connection. Even though this class is fully
thread-safe it ought to be used by one execution thread only, as only
one thread a time can lease the connection at a time."

Try creating the HttpClient object with its Builder instead.  Here's one
example:

RequestConfig rc = RequestConfig.custom().setConnectTimeout(5000)
  .setSocketTimeout(300000).build();
HttpClient client = HttpClients.custom().setDefaultRequestConfig(rc)
  .setMaxConnPerRoute(1024).setMaxConnTotal(4096)
  .disableAutomaticRetries().build();

Thanks,
Shawn