Monday, April 10, 2023

What is Apache Sling :: Connection Timeout Agent and How to use it in AEM?

Apache Sling :: Connection Timeout Agent provides a Java agent that uses the instrumentation API to add connect and read timeouts to connections made via HTTP or HTTPs. It only applies these timeouts if none were set explicitly.

The agent is intended as an additional layer of control when running untrusted client code that may make calls without explicitly setting timeouts. Setting timeouts in client code is always recommended rather than relying on this agent.

It currently supports setting timeouts for HTTP connections done using:

  • and/or
  • Apache Commons HttpClient 3.x
  • Apache HttpComponents Client 4.x
  • OK Http

Enable the agent configurations through Java CLI.

You can check out the code from Tags · apache/sling-org-apache-sling-connection-timeout-agent ( and build locally (mvn clean install)

I am using the snapshot version for testing with Connect timeout as 20 secs and Read time out as 60 secs (Copy next to the AEM jar file)

java,60000 -jar aem-sdk-quickstart-2022.9.8722.20220912T101352Z-220800.jar
  • <agent-connect-timeout> - connection timeout in milliseconds to apply via the agent
  • <agent-read-timeout>- read timeout in milliseconds to apply via the agent
  • <logspec> - if set to v, it will enter verbose mode and print additional information to System.out
The Connection Timeout Agent is beneficial to handle some worst-case scenarios — e.g., we were using Adobe Search and Promote to implement the content search for websites; when the Adobe Search and Promote was retired, we migrated to a different search engine, but the S&P code and configurations were not cleaned up; we faced huge performance issue on the day the S&P API’s were stopped working the actual root cause was due to missing connect timeout all the reads were struck indefinitely that caused other requests to get slowed down. The issue could have been arrested if this agent had been configured already.

For testing purposes, the servlet code enabled as part of my last post How to Connect Adobe Experience Manager (AEM) with ChatGPT | by Albin Issac | Apr, 2023 | Medium was not enabled with connection/read timeouts; enabled the connection timeout as one means the connection should fail all the times

java,60000 -jar aem-sdk-quickstart-2022.9.8722.20220912T101352Z-220800.jar

Yes, the connection started failing every time; it started working without any issue when I set 20 seconds as the Connection timeout and 60 seconds as the read timeout.

org.apache.http.conn.ConnectTimeoutException: Connect to [,] failed: connect timed out

The configurations can be monitored through JMX —

The AMS started enabling the connection timeout agent for the customers hosted on the AMS platform — The default connection timeout will be set to 20 seconds, and the default read timeout will be set to 60 seconds. But you can work with the AMS team to adjust the timeout values based on your custom need. The agent can be configured in on-prem/custom cloud-hosted versions of AEM if required.

I assume AEM as Cloud Services by default enabled with the Connection Time out agent — These timeout values are 10 seconds for connect calls and 60 seconds for read calls for connections. Refer to AEM as a Cloud Service Development Guidelines | Adobe Experience Manager (Outgoing HTTP Connections) for more details; not sure if the customers can adjust the global timeout values.

Anyhow recommended to always set the connection and read time outs in the code as the global configurations can lead to different issues.

Refer to Apache Sling :: Connection Timeout Agent for more details on Connection Timeout Agent.

No comments:

Post a Comment