New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

J4pClient does not support server failures #14

Closed
ludovicc opened this Issue Nov 26, 2010 · 3 comments

Comments

Projects
None yet
2 participants
@ludovicc

ludovicc commented Nov 26, 2010

While having a J4pClient which sends periodic requests on a server, I restarted that server.
There was a 404 error, probably caused by a request sent during server restart, but then J4p failed with the message "Invalid use of SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one."

20:27:30.062 [main] ERROR c.b.metrics.harvest.HarvestMetrics - Error - cannot harvest metric
org.jolokia.client.exception.J4pException: 404 Not Found
at org.jolokia.client.J4pClient.extractJsonResponse(J4pClient.java:110) ~[jolokia-client-java-0.80.jar:na]
at org.jolokia.client.J4pClient.execute(J4pClient.java:83) ~[jolokia-client-java-0.80.jar:na]
at org.jolokia.client.J4pClient.execute(J4pClient.java:66) ~[jolokia-client-java-0.80.jar:na]
at com.b.metrics.harvest.HarvestMetrics.execute(HarvestMetrics.java:101) [classes/:na]
at com.b.metrics.harvest.HarvestMetrics.main(HarvestMetrics.java:281) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_22]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_22]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_22]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_22]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115) [idea_rt.jar:na]
Harvesting com.b.metrics:type=GroupOfMetrics,name=ApplicationCollector
20:28:30.066 [main] ERROR c.b.metrics.harvest.HarvestMetrics - Error - cannot harvest metric
java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
at org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:199) ~[httpclient-4.0.1.jar:4.0.1]
at org.apache.http.impl.conn.SingleClientConnManager$1.getConnection(SingleClientConnManager.java:173) ~[httpclient-4.0.1.jar:4.0.1]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:390) ~[httpclient-4.0.1.jar:4.0.1]
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641) ~[httpclient-4.0.1.jar:4.0.1]
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576) ~[httpclient-4.0.1.jar:4.0.1]
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554) ~[httpclient-4.0.1.jar:4.0.1]
at org.jolokia.client.J4pClient.execute(J4pClient.java:82) ~[jolokia-client-java-0.80.jar:na]
at org.jolokia.client.J4pClient.execute(J4pClient.java:66) ~[jolokia-client-java-0.80.jar:na]
at com.b.metrics.harvest.HarvestMetrics.execute(HarvestMetrics.java:101) [classes/:na]

@rhuss

This comment has been minimized.

Owner

rhuss commented Nov 26, 2010

This error typically occurs in multi threaded environments, but can happen if a response is not properly consumed. Thanks for spotting this. I fixed this by

a) making sure that the response is consumed (and the connection released) even in an error case
b) switched from a SingleClientConnManager to a ThreadSafeClientConnManager in Apache's HttpClient.

Expect this for version 0.81, I still need some tuning for allowing to select the connection manager (and other parameters like timeouts) during construction of the client.

@rhuss

This comment has been minimized.

Owner

rhuss commented Nov 26, 2010

Pushed changes to GIT and extended the construction of the J4pClient with a builder for tuning various parameters like timeouts. By default, the threadsafe connection manager is used now

Example:

J4pClient.url("http://...")
.pooledConnections()
.maxTotalConnections(20)
.connectionTimeout(500)
.build()

@ludovicc

This comment has been minimized.

ludovicc commented Feb 18, 2011

This looks good and seems to work, thanks

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment