I have a multi-threaded stress test that, when under heavy load concurrently
opening many HttpClient connections, intermittently receives
an IllegalArgumentException with the following stack trace:
Exception in thread "pool-3-thread-24" java.lang.IllegalArgumentException:
host parameter is null
at
org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:206)
at
org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:155)
at
org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnectionWithTimeout(SimpleHttpConnectionManager.java:175)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
Again- only intermittently under heavy connect load. There appears some sort
of timing-related error in HttpClient. Perhaps around setting up the
following chain in HttpMethodDirector.executeMethod, line 134
// Link all parameter collections to form the hierarchy:
// Global -> HttpClient -> HostConfiguration -> HttpMethod
this.hostConfiguration.getParams().setDefaults(this.params);
method.getParams().setDefaults(this.hostConfiguration.getParams());
Possibly the params management is not fully thread-safe, or, the OS, on
occasion, doesn't resolve the hostname quickly enough. In any case, the
workaround I've found for this is to explicitly set the HostConfiguration
before creating the GetMethod:
val manager = new SimpleHttpConnectionManager(true)
val client = new HttpClient(manager)
// Attempt to work around NTE in HttpConnection.java:206
val hostConfiguration = new HostConfiguration()
hostConfiguration.setHost(host, port)
client.setHostConfiguration(hostConfiguration)
val getter = new GetMethod(url)
So far this has eliminated this intermittent failure.
-John Kalucki