{"record":{"id":"82322f5f510baa6b","repo":"elastic/elasticsearch","slug":"too-many-redirects-connection-to","errorCode":null,"errorMessage":"too many redirects connection to [{}]","messagePattern":"too many redirects connection to \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/ip-location/src/main/java/org/elasticsearch/ingest/geoip/HttpClient.java","lineNumber":98,"sourceCode":"    InputStream get(final PasswordAuthentication auth, final String url) throws IOException {\n        Objects.requireNonNull(auth);\n        Objects.requireNonNull(url);\n\n        final String originalAuthority = new URL(url).getAuthority();\n\n        String innerUrl = url;\n        HttpURLConnection conn = createConnection(auth, innerUrl);\n\n        int redirectsCount = 0;\n        while (true) {\n            switch (conn.getResponseCode()) {\n                case HTTP_OK:\n                    return getInputStream(conn);\n                case HTTP_MOVED_PERM:\n                case HTTP_MOVED_TEMP:\n                case HTTP_SEE_OTHER:\n                    if (redirectsCount++ > 50) {\n                        throw new IllegalStateException(\"too many redirects connection to [\" + url + \"]\");\n                    }\n\n                    // deal with redirections (including relative urls)\n                    final String location = conn.getHeaderField(\"Location\");\n                    final URL base = new URL(innerUrl);\n                    final URL next = new URL(base, location);\n                    innerUrl = next.toExternalForm();\n\n                    // compare the *original* authority and the next authority to determine whether to include auth details.\n                    // this means that the host and port (if it is provided explicitly) are considered. it also means that if we\n                    // were to ping-pong back to the original authority, then we'd start including the auth details again.\n                    final String nextAuthority = next.getAuthority();\n                    if (originalAuthority.equals(nextAuthority)) {\n                        conn = createConnection(auth, innerUrl);\n                    } else {\n                        conn = createConnection(NO_AUTH, innerUrl);\n                    }\n                    break;","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ip-location/src/main/java/org/elasticsearch/ingest/geoip/HttpClient.java#L80-L116","documentation":"Thrown by HttpClient.get after following more than 50 HTTP 301/302/303 redirects for a single request. The client manually follows redirects (to control auth propagation across authorities); a redirect chain longer than 50 is treated as a loop or a broken endpoint. IllegalStateException propagates as an IOException-adjacent failure of the download.","triggerScenarios":"HttpClient.get(auth, url) loop on HTTP_MOVED_PERM/HTTP_MOVED_TEMP/HTTP_SEE_OTHER increments redirectsCount; once it exceeds 50, IllegalStateException is thrown.","commonSituations":"Misconfigured endpoint that redirects back to itself; a CDN/auth combo that ping-pongs between two hosts; the originalAuthority vs nextAuthority logic re-including auth and re-triggering an auth redirect; provider outage returning a redirect to a status page that itself redirects.","solutions":["Inspect the URL in the message; curl it with -L --max-redirs 60 to see the redirect chain.","Fix or replace the endpoint configuration so it resolves without a loop.","If a proxy is rewriting redirects, bypass or reconfigure it for the geoip download host.","Report to the provider if their endpoint is genuinely looping."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    InputStream in = httpClient.get(auth, url);\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"too many redirects\")) {\n        // curl the URL to inspect the chain; fix endpoint config or bypass redirecting proxy\n    } else throw e;\n}","preventionTips":["Pre-resolve endpoint URLs to avoid redirect-heavy hosts.","Do not point geoip downloads at hosts that redirect to themselves or to auth pages that loop.","Watch for proxy-injected redirects and bypass them for the geoip host.","Cap redirect following and log the chain when the cap is hit."],"tags":["geoip","http","redirect","network","download"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}