hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Kalucki" <b...@kalucki.com>
Subject Workaround for intermittent IllegalArgumentException: host parameter is null
Date Fri, 09 Jan 2009 19:26:00 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message