{"record":{"id":"472cff1bf7b099f6","repo":"SeleniumHQ/selenium","slug":"invalid-port-port-472cff","errorCode":null,"errorMessage":"invalid port: #{@port}","messagePattern":"invalid port: #(.+?)","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/service_manager.rb","lineNumber":47,"sourceCode":"      START_TIMEOUT = 20\n      SOCKET_LOCK_TIMEOUT = 45\n      STOP_TIMEOUT = 20\n\n      #\n      # End users should use a class method for the desired driver, rather than using this directly.\n      #\n      # @api private\n      #\n\n      def initialize(config)\n        @executable_path = config.executable_path\n        @host = Platform.localhost\n        @port = config.port\n        @io = config.log\n        @extra_args = config.args\n        @shutdown_supported = config.shutdown_supported\n\n        raise Error::WebDriverError, \"invalid port: #{@port}\" if @port < 1\n      end\n\n      def start\n        raise \"already started: #{uri.inspect} #{@executable_path.inspect}\" if process_running?\n\n        Platform.exit_hook { stop } # make sure we don't leave the server running\n\n        socket_lock.locked do\n          find_free_port\n          start_process\n          connect_until_stable\n        end\n      end\n\n      def stop\n        return unless @shutdown_supported\n        return if process_exited?\n","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/service_manager.rb#L29-L65","documentation":"Raised by ServiceManager#initialize when the config.port value is less than 1. ServiceManager is the internal class that launches and manages the driver server process. This mirrors the Service#initialize check (error 429); if a Service is constructed with an invalid port and passed to ServiceManager, this guard fires.","triggerScenarios":"A Service object is created with port < 1 but the check in Service is somehow bypassed (e.g., by directly mutating attr_accessor :port before launch). A custom config object passed to ServiceManager with port set to 0 or negative. Subclass overriding initialize without calling super properly.","commonSituations":"Directly assigning service.port = 0 after construction (the attr_accessor bypasses the initialize guard). Custom Service subclass that overrides initialize and sets @port incorrectly. Programmatic port manipulation between Service creation and ServiceManager.new.","solutions":["Do not mutate service.port after construction; set it via the port: keyword in Service.new.","Ensure any custom Service subclass calls super and preserves the port validation.","Validate port before assigning: service.port = valid_port if valid_port > 0."],"exampleFix":"// before\nservice = Selenium::WebDriver::Service.chrome\nservice.port = 0  # bypasses initialize guard\nservice.launch  # ServiceManager.new raises\n\n// after\nservice = Selenium::WebDriver::Service.chrome(port: 9515)\nservice.launch","handlingStrategy":"validation","validationCode":"# Ensure port is valid before launching service\nservice = Selenium::WebDriver::Service.chrome(port: 9515)\nif service.port.nil? || service.port < 1\n  raise \"Invalid port configured: #{service.port}\"\nend\nservice.launch","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mutate service.port after construction; always set it via the port: keyword arg.","If you must change the port, create a new Service instance instead.","Custom Service subclasses must call super in initialize to preserve port validation."],"tags":["service-manager","port","configuration","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}