apache/druid · error · IllegalArgumentException

Cannot figure out default port for protocol[%s], please set

Error message

Cannot figure out default port for protocol[%s], please set Host header.

What it means

NettyHttpClient.getHost derives a 'host:port' string from the request URL. If the URL carries no explicit port and the protocol is not http or https (e.g. some custom or mistyped scheme), the client cannot infer a default port and throws IAE, advising the caller to set the Host header explicitly.

Source

Thrown at processing/src/main/java/org/apache/druid/java/util/http/client/NettyHttpClient.java:465

      return 0;
    } else {
      return timeout;
    }
  }

  private String getHost(URL url)
  {
    int port = url.getPort();

    if (port == -1) {
      final String protocol = url.getProtocol();

      if ("http".equalsIgnoreCase(protocol)) {
        port = 80;
      } else if ("https".equalsIgnoreCase(protocol)) {
        port = 443;
      } else {
        throw new IAE("Cannot figure out default port for protocol[%s], please set Host header.", protocol);
      }
    }

    return url.getHost() + ":" + port;
  }

  private String getPoolKey(URL url)
  {
    return url.getProtocol() + "://" + url.getHost() + ":"
           + (url.getPort() == -1 ? url.getDefaultPort() : url.getPort());
  }
}

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Fix the URL scheme to http:// or https://.
  2. Include an explicit port in the URL (e.g. http://host:8080/path) so no default is needed.
  3. Set the Host header (host:port) on the request as the error message suggests.
  4. Validate/normalize configured URLs before passing them to the HttpClient.

Example fix

// before
String url = "htp://broker:8082/druid/v2"; // bad scheme, no default port
// after
String url = "http://broker:8082/druid/v2";
Defensive patterns

Strategy: validation

Validate before calling

java.net.URL u = new java.net.URL(rawUrl);
String scheme = u.getProtocol();
if (!scheme.equals("http") && !scheme.equals("https")) {
  throw new IllegalArgumentException("URL must use http/https: " + rawUrl);
}
if (u.getPort() == -1 && u.getDefaultPort() == -1) { /* add explicit port */ }

Prevention

When it happens

Trigger: Executing a request whose URL protocol is not http/https and whose authority lacks a port — e.g. typo'd scheme like 'htp://host/path' or a custom protocol, with no Host header set.

Common situations: Hand-built URLs with malformed schemes; config properties containing wrong protocol prefixes; proxy setups where a custom scheme was mistakenly used.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/cef07cce30122d0b. Report an issue: GitHub.