Issue
We are using Liferay URLtoString method from com.liferay.portal.kernel.util.HttpUtil in our custom development to call an external web service
We are getting ConnectionPoolTimeoutException: Timeout waiting for connection from pool exception when our custom development calls the external web service:
java.io.IOException: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
at com.liferay.portal.util.HttpImpl.URLtoInputStream(HttpImpl.java:1902)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:1588)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:1178)
at com.liferay.portal.util.HttpImpl.URLtoString(HttpImpl.java:1240)
at com.liferay.portal.kernel.util.HttpUtil.URLtoString(HttpUtil.java:315)
[...omitted...]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1726)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:313)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:279)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:191)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at com.liferay.portal.util.HttpImpl.URLtoInputStream(HttpImpl.java:1783)
... 235 more
How can we avoid this error?
Environment
- Any Liferay version
Resolution
- max. connections per host: 2
- max total connections: 20
- timeout: 10 seconds
Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:313)
portal-ext.properties file through the properties:com.liferay.portal.util.HttpImpl.max.connections.per.host=2
com.liferay.portal.util.HttpImpl.max.total.connections=20
com.liferay.portal.util.HttpImpl.timeout=10000
Note that the properties
com.liferay.portal.util.HttpImpl.max.connections.per.host and com.liferay.portal.util.HttpImpl.timeout can be specified for a particular host, for example, if we want to restrict to www.google.com:com.liferay.portal.util.HttpImpl.max.connections.per.host[www.google.com]=2
There is more information about how to configure these properties in the following page:
Warning: these properties will affect to all places where Liferay uses the HttpUtil utility so be careful and if you increase it, verify that the new value does not affect the overall performance of your system.
Additional Information