This module 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 to use when running untrusted client code that may make calls without explicitly setting timeouts. It is always recommended to set timeouts in client code, rather than relying on this agent.
It currently supports setting timeouts for HTTP connections done using:
The agent can be loaded using the standard Java CLI invocation, by using the
java -javaagent:org.apache.sling.connection-timeout-agent-jar-with-dependencies.jar=<agent-connect-timeout>,<agent-read-timeout>[,<logspec>] -jar org.apache.sling.starter-11.jar
It support two mandatory arguments and an optional one:
<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
If started in verbose mode, output similar to the following will be printed
[AGENT] Preparing to install URL transformers. Configured timeouts - connectTimeout : 1000, readTimeout: 1000 [AGENT] All transformers installed [AGENT] JavaNetTimeoutTransformer asked to transform sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection [AGENT] Transformation of sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection complete [AGENT] JavaNetTimeoutTransformer asked to transform sun/net/www/protocol/http/HttpURLConnection [AGENT] Transformation of sun/net/www/protocol/http/HttpURLConnection complete
Note that classes will be transformed when they are loaded. It is expected for a transformer for class A to be active but the class not to be transformed until it is actually used.
Various runtime information is exposed through a JMX MBean registered at
It is always recommended to set timeouts in the client code directly. The agent carries some risks, namely:
All HTTP client libraries offer a way of setting connect and read timeouts, and it strongly recommended to do so. Alternatively, various bundles offer a way of centrally defining timeouts, amongst them: