Details
-
Bug
-
Status: Resolved
-
Critical
-
Resolution: Fixed
-
1.7.3
-
None
-
Ubuntu 16.04, OpenJDK 7
Description
When using HTTP Client 4 with a generated WSDL-Client the HTTP connections are not returned properly to underlying connection pool. The HTTP connections are still allocated, when new requests are made. This ends up in waiting for HTTP connections from pool, but no connections are available anymore.
The connections should be returned to pool as stated in the Apache HTTP Client 4 documentation (2.3.1):
https://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html
Here is some example code to reproduce the problem. The BLZServiceStub is a generated WSDL client (wsdl2java) of the following service: http://www.thomas-bayer.com/axis2/services/BLZService?wsdl . But the problem is independent of the used service.
package com.thomas_bayer.blz; import java.rmi.RemoteException; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.CoreConnectionPNames; import org.apache.http.params.HttpParams; public class TestRunner { private static final int timeoutMillis = 5000; private static final int maxConnections = 2; private static final String[] BLZs = new String[] { "12030000", "12070000" }; public static void main(String[] args) throws RemoteException { BLZServiceStub blzService = new BLZServiceStub(); blzService._getServiceClient().getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, buildHttpClient()); for(int i = 0; i <= maxConnections; i++) { BLZServiceStub.GetBankType getBankType = new BLZServiceStub.GetBankType(); getBankType.setBlz(BLZs[i % BLZs.length]); BLZServiceStub.GetBank getBank = new BLZServiceStub.GetBank(); getBank.setGetBank(getBankType); System.out.println("Querying for bank (iteration: " + i + ")"); BLZServiceStub.GetBankResponse response = blzService.getBank(getBank); System.out.println("Bank queried"); System.out.println("Result: " + response.getGetBankResponse().getDetails().getBezeichnung()); } } protected static HttpClient buildHttpClient() { final PoolingClientConnectionManager conmgr = new PoolingClientConnectionManager(); conmgr.setDefaultMaxPerRoute(maxConnections); conmgr.setMaxTotal(maxConnections); final HttpParams params = new BasicHttpParams(); params.setLongParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeoutMillis); params.setLongParameter(CoreConnectionPNames.SO_TIMEOUT, timeoutMillis); return new DefaultHttpClient(conmgr, params); } }
Running this code will produce the following output:
Querying for bank (iteration: 0) Bank queried Result: Deutsche Kreditbank Berlin Querying for bank (iteration: 1) Bank queried Result: Deutsche Bank Ld Brandenburg Querying for bank (iteration: 2) Sep 27, 2016 8:32:43 AM org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl sendViaPost INFORMATION: Unable to sendViaPost to url[http://www.thomas-bayer.com/axis2/services/BLZService] org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool at org.apache.http.impl.conn.PoolingClientConnectionManager.leaseConnection(PoolingClientConnectionManager.java:232) at org.apache.http.impl.conn.PoolingClientConnectionManager$1.getConnection(PoolingClientConnectionManager.java:199) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:456) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.executeMethod(HTTPSenderImpl.java:873) at org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.sendViaPost(HTTPSenderImpl.java:238) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:121) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:403) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:234) at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:399) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) at com.thomas_bayer.blz.BLZServiceStub.getBank(BLZServiceStub.java:162) at com.thomas_bayer.blz.TestRunner.main(TestRunner.java:34) Exception in thread "main" org.apache.axis2.AxisFault: Timeout waiting for connection from pool at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.sendViaPost(HTTPSenderImpl.java:242) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:121) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:403) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:234) at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:431) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:399) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150) at com.thomas_bayer.blz.BLZServiceStub.getBank(BLZServiceStub.java:162) at com.thomas_bayer.blz.TestRunner.main(TestRunner.java:34) Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool at org.apache.http.impl.conn.PoolingClientConnectionManager.leaseConnection(PoolingClientConnectionManager.java:232) at org.apache.http.impl.conn.PoolingClientConnectionManager$1.getConnection(PoolingClientConnectionManager.java:199) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:456) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.executeMethod(HTTPSenderImpl.java:873) at org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl.sendViaPost(HTTPSenderImpl.java:238) ... 9 more
The exception is thrown after some timeout waiting for the connection manager to return a connection. The problem even arised, when i do not set any cached http client. In that case the problem will arise after 200 requests (default number of pooled connections within axis2)
Attachments
Issue Links
- is duplicated by
-
AXIS2-5811 org.apache.axis2.AxisFault: Timeout waiting for connection from pool
- Resolved
-
AXIS2-5845 [axis2-transport-http] HTTPSenderImpl doesn't close HttpGet, HttpPost objects
- Resolved