{"record":{"id":"d8ecd0d78f6bffeb","repo":"SeleniumHQ/selenium","slug":"empty-body-content-type-inspect-code-bo","errorCode":null,"errorMessage":"empty body: #{content_type.inspect} (#{code})\n#{body}","messagePattern":"empty body: #(.+?) \\(#(.+?)\\)\n#(.+?)","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/remote/http/common.rb","lineNumber":146,"sourceCode":"              result = str.dup.force_encoding(Encoding::UTF_8)\n              return result if result.valid_encoding?\n            end\n\n            str.encode(Encoding::UTF_8)\n          rescue EncodingError => e\n            raise Error::WebDriverError,\n                  \"Unable to encode string to UTF-8: #{e.message}. \" \\\n                  \"String encoding: #{str.encoding}, content: #{str.inspect}\"\n          end\n\n          def create_response(code, body, content_type)\n            code = code.to_i\n            body = body.to_s.strip\n            content_type = content_type.to_s\n            WebDriver.logger.debug(\"<- #{body}\", id: :command)\n\n            if content_type.include? CONTENT_TYPE\n              raise Error::WebDriverError, \"empty body: #{content_type.inspect} (#{code})\\n#{body}\" if body.empty?\n\n              Response.new(code, JSON.parse(body))\n            elsif code == 204\n              Response.new(code)\n            else\n              msg = if body.empty?\n                      \"unexpected response, code=#{code}, content-type=#{content_type.inspect}\"\n                    else\n                      \"unexpected response, code=#{code}, content-type=#{content_type.inspect}\\n#{body}\"\n                    end\n\n              raise Error::WebDriverError, msg\n            end\n          end\n        end # Common\n      end # Http\n    end # Remote\n  end # WebDriver","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/remote/http/common.rb#L128-L164","documentation":"Raised as Error::WebDriverError by Http::Common#create_response when the response has a JSON content-type but the body is empty (after stripping). A JSON content-type promises a parseable JSON body; an empty body means the server violated its own contract, so JSON.parse would fail. The error includes the content-type and status code for diagnosis.","triggerScenarios":"The remote Selenium Server returns Content-Type: application/json with a 200 status but zero-length body. A proxy or load balancer strips the body but preserves headers. The server crashes mid-response after sending headers. A misconfigured grid router returns an empty JSON response.","commonSituations":"Selenium Grid node crashes during session creation. Reverse proxies (nginx, Envoy) misconfigured to buffer/truncate responses. Network interruptions that close the connection after headers. Server Out-Of-Memory kills that truncate the response. Cloud provider endpoints with buggy response handling.","solutions":["Check Selenium Server / Grid logs for crashes or errors at the time of the request.","Inspect network infrastructure (proxies, load balancers) for response body truncation.","Retry the request; transient empty bodies from server restarts often succeed on retry.","Verify server health and resource limits (memory, file descriptors) on the grid nodes."],"exampleFix":"# No code fix; diagnose server-side:\n# 1. Check grid node logs for crashes\n# 2. Verify proxy configuration preserves response bodies\n# Retry transient failures:\n# begin\n#   driver.navigate.to(url)\n# rescue Selenium::WebDriver::Error::WebDriverError => e\n#   retry if e.message.include?('empty body')\n# end","handlingStrategy":"retry","validationCode":"# No caller-side prevention; this is a server-side response contract violation.\n# Monitor server health proactively:\n# Net::HTTP.get(URI('http://grid:4444/status'))","typeGuard":null,"tryCatchPattern":"retries = 0\nbegin\n  driver.navigate.to(url)\nrescue Selenium::WebDriver::Error::WebDriverError => e\n  raise unless e.message.include?('empty body') && retries < 3\n  retries += 1\n  sleep 2 ** retries\n  retry\nend","preventionTips":["Monitor Selenium Server / Grid health and resource usage (memory, FDs).","Check proxy/load-balancer configs for response body truncation.","Implement retry logic for transient empty-body responses.","Keep the Selenium Server and client gem versions aligned."],"tags":["http-response","empty-body","json","server-error","network"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}