{"record":{"id":"ff2b155e4db46757","repo":"SeleniumHQ/selenium","slug":"remote-server-not-stopped-in-timeout-seconds","errorCode":null,"errorMessage":"remote server not stopped in #{@timeout} seconds","messagePattern":"remote server not stopped in #(.+?) seconds","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/server.rb","lineNumber":294,"sourceCode":"      start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)\n      loop do\n        return if status_ok?\n\n        elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time\n        raise Error, \"remote server not ready in #{@timeout} seconds\" if elapsed > @timeout\n\n        sleep 0.5\n      end\n    end\n\n    def socket_connected?\n      @socket_connected ||= socket.connected?\n    end\n\n    def poll_for_shutdown\n      return if socket.closed?\n\n      raise Error, \"remote server not stopped in #{@timeout} seconds\"\n    end\n\n    def socket\n      @socket ||= WebDriver::SocketPoller.new(@host, @port, @timeout)\n    end\n  end # Server\nend # Selenium\n","sourceCodeStart":276,"sourceCodeEnd":302,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/server.rb#L276-L302","documentation":"Selenium::Server wraps the standalone Selenium Grid/server jar process. After you request a shutdown, poll_for_shutdown checks the listening socket (via SocketPoller); if the server's port is still accepting connections past @timeout seconds, this Error is raised because the server never came down. It is a liveness check on a process you asked to stop.","triggerScenarios":"Calling Selenium::Server#stop (or letting a server with a block go out of scope) where the managed server jar keeps the TCP port open longer than the configured @timeout. Triggered whenever stop poll_for_shutdown finds socket.closed? still false at the end of the wait window.","commonSituations":"Server jar version mismatch/hang, slow JVM/container startup of shutdown, another process (or a previous stale java instance) holding the port, very low timeout default on a loaded CI machine, host/port misconfigured so SocketPoller probes the wrong service.","solutions":["Pass a larger shutdown timeout, e.g. server.stop(60), or Selenium::Server.new(..., timeout: 60).","Confirm the port is actually the Selenium server: `lsof -i :<port>` / `netstat` and that no stale java process holds it.","Kill any orphaned server process from a previous run before starting a new one.","Use a server jar version matching your Selenium client version, and ensure the host/port passed to Selenium::Server match the real listener.","Call server.stop in an ensure block and rescue Selenium::WebDriver::Error to avoid masking test failures."],"exampleFix":"// before\nserver = Selenium::Server.new('/path/selenium-server.jar')\nserver.stop\n// after\nserver = Selenium::Server.new('/path/selenium-server.jar', timeout: 90)\nat_exit { server.stop(90) rescue nil }","handlingStrategy":"validation","validationCode":"require 'socket'\n\n# Before stop: confirm the host/port is the Selenium server and pick a sane timeout.\ndef selenium_port_open?(host, port)\n  sock = TCPSocket.new(host, port) rescue nil\n  return false unless sock\n  sock.close\n  true\nend\n\nserver.stop(selenium_port_open?(host, port) ? 90 : 10)","typeGuard":null,"tryCatchPattern":"begin\n  server.stop(90)\nrescue Selenium::WebDriver::Error => e\n  warn \"Server did not stop in time: #{e.message}\"\n  # leave it; OS will reap, or kill by PID\nend","preventionTips":["Always wrap server.stop in an ensure block and rescue Selenium::WebDriver::Error.","Pass an explicit, generous timeout for shutdown on slow/CI environments.","Track the server PID so you can kill it if poll_for_shutdown times out.","Reap stale java/server processes before starting a fresh Selenium::Server."],"tags":["server","shutdown","timeout","network","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}