{"record":{"id":"4ec98bde3f952014","repo":"SeleniumHQ/selenium","slug":"too-many-redirects","errorCode":null,"errorMessage":"too many redirects","messagePattern":"too many redirects","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/remote/http/default.rb","lineNumber":128,"sourceCode":"              sleep 2\n              retry\n            rescue Errno::ECONNREFUSED => e\n              raise e.class, \"using proxy: #{proxy.http}\" if use_proxy?\n\n              raise\n            end\n\n            if response.is_a? Net::HTTPRedirection\n              follow_redirect(response, redirects)\n            else\n              WebDriver.logger.debug(\"   <<<  #{response.instance_variable_get(:@header).inspect}\", id: :header)\n              create_response response.code, response.body, response.content_type\n            end\n          end\n\n          def follow_redirect(response, redirects)\n            WebDriver.logger.debug(\"Redirect to #{response['Location']}; times: #{redirects}\", id: :redirect)\n            raise Error::WebDriverError, 'too many redirects' if redirects >= client_config.max_redirects\n\n            request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)\n          end\n\n          def new_request_for(verb, url, headers, payload)\n            req = Net::HTTP.const_get(verb.to_s.capitalize).new(url.path, headers)\n\n            req.basic_auth server_url.user, server_url.password if server_url.userinfo\n\n            req.body = payload if payload\n\n            req\n          end\n\n          def response_for(request)\n            http.request request\n          end\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/remote/http/default.rb#L110-L146","documentation":"Raised as Error::WebDriverError by Http::Default#follow_redirect when the redirect count reaches client_config.max_redirects. The Default adapter manually follows HTTP 3xx redirects by re-issuing GET requests to the Location header; each follow increments a counter and this error prevents infinite redirect loops.","triggerScenarios":"The Selenium Server or an intermediate proxy responds with a redirect chain longer than max_redirects (default typically 20). A redirect loop (A -> B -> A) that never terminates. The server redirecting every request including the redirect target.","commonSituations":"Grid behind a reverse proxy with redirect loops due to trailing-slash or scheme (http/https) mismatches. Load balancer health-check redirects. Corporate proxies that redirect authentication. Server misconfiguration with http-to-https redirect loops when the client can't follow the scheme change.","solutions":["Increase client_config.max_redirects if the redirect chain is legitimately long but finite.","Diagnose the redirect loop: enable redirect logging (id: :redirect) to see each Location and the counter.","Fix the server/proxy configuration causing the loop — often a trailing-slash or http/https scheme mismatch.","Ensure the server_url has the correct scheme and path so the initial request doesn't trigger redirects."],"exampleFix":"# before — default max_redirects too low or server has a loop\nclient = Selenium::WebDriver::Remote::Http::Default.new\n\n# after — increase limit if chain is legitimate\nconfig = Selenium::WebDriver::Remote::ClientConfig.new(server_url: url, max_redirects: 50)\nclient = Selenium::WebDriver::Remote::Http::Default.new(client_config: config)\n# Diagnose loops with:\n# Selenium::WebDriver.logger.level = :debug  # watch id: :redirect","handlingStrategy":"retry","validationCode":"# Pre-flight: check the URL does not immediately redirect in a loop\nrequire 'net/http'\nuri = URI(server_url)\nNet::HTTP.start(uri.host, uri.port) { |http| http.head(uri.path) }\n# If this itself loops, fix the server/proxy before proceeding.","typeGuard":null,"tryCatchPattern":"retries = 0\nbegin\n  driver.navigate.to(url)\nrescue Selenium::WebDriver::Error::WebDriverError => e\n  raise unless e.message.include?('too many redirects')\n  raise 'Redirect loop — fix server/proxy config' if retries >= 2\n  retries += 1\n  sleep 1\n  retry\nend","preventionTips":["Enable redirect debug logging (id: :redirect) to diagnose loops.","Ensure server_url uses the correct scheme (http/https) and trailing slash.","Check reverse proxy configs for redirect loops.","Increase max_redirects on ClientConfig if the chain is legitimately long."],"tags":["http-client","redirect","network","config-mistake","proxy"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}