Bug 1465072 - Force IPv4 for marionette::get_free_port(). r=whimboo
authorAndreas Tolfsen <ato@sny.no>
Tue, 29 May 2018 14:53:51 +0100
changeset 801198 4ad07f3127fe38342e73b49f7cf282950b1ae73f
parent 801197 50c588f317f497fc8fa43fc38116270b067d8c78
child 801199 d4bfc66b1fb9080dd06e33d549d255b61e28aa94
push id111603
push usermozilla@kaply.com
push dateTue, 29 May 2018 22:12:07 +0000
reviewerswhimboo
bugs1465072, 1462040
milestone62.0a1
Bug 1465072 - Force IPv4 for marionette::get_free_port(). r=whimboo As part of bug 1462040, geckodriver was made to use the IPv4 stack when connecting to Marionette in Firefox. However, the helper function for finding an atomic free port still uses localhost, which on some systems may prefer the IPv6 stack. To ensure that the free port is found on the correct IP stack, this patch changes marionette::get_free_port() to use the DEFAULT_HOST constant that is already used for establishing the connection. MozReview-Commit-ID: HeEyvwYfHh2
testing/geckodriver/src/marionette.rs
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -49,17 +49,18 @@ use webdriver::common::{Date, ELEMENT_KE
 use webdriver::error::{ErrorStatus, WebDriverError, WebDriverResult};
 use webdriver::server::{WebDriverHandler, Session};
 use webdriver::httpapi::{WebDriverExtensionRoute};
 
 use capabilities::{FirefoxCapabilities, FirefoxOptions};
 use logging;
 use prefs;
 
-// Bind host to IPv4 only because Marionette only listens on that interface
+// localhost may be routed to the IPv6 stack on certain systems,
+// and nsIServerSocket in Marionette only supports IPv4
 const DEFAULT_HOST: &'static str = "127.0.0.1";
 
 const CHROME_ELEMENT_KEY: &'static str = "chromeelement-9fc5-4b51-a3c8-01716eedeb04";
 const LEGACY_ELEMENT_KEY: &'static str = "ELEMENT";
 
 pub fn extension_routes() -> Vec<(Method, &'static str, GeckoExtensionRoute)> {
     return vec![(Method::Get, "/session/{sessionId}/moz/context", GeckoExtensionRoute::GetContext),
              (Method::Post, "/session/{sessionId}/moz/context", GeckoExtensionRoute::SetContext),
@@ -418,17 +419,17 @@ impl MarionetteHandler {
                                                                  &mut capabilities));
             (options, capabilities)
         };
 
         if let Some(l) = options.log.level {
             logging::set_max_level(l);
         }
 
-        let port = self.settings.port.unwrap_or(try!(get_free_port()));
+        let port = self.settings.port.unwrap_or(get_free_port()?);
         if !self.settings.connect_existing {
             try!(self.start_browser(port, options));
         }
 
         let mut connection = MarionetteConnection::new(port, session_id.clone());
         try!(connection.connect(&mut self.browser));
         self.connection = Mutex::new(Some(connection));
 
@@ -1314,17 +1315,17 @@ impl Into<WebDriverError> for Marionette
             WebDriverError::new_with_stack(status, message, stack)
         } else {
             WebDriverError::new(status, message)
         }
     }
 }
 
 fn get_free_port() -> IoResult<u16> {
-    TcpListener::bind(&("localhost", 0))
+    TcpListener::bind((DEFAULT_HOST, 0))
         .and_then(|stream| stream.local_addr())
         .map(|x| x.port())
 }
 
 pub struct MarionetteConnection {
     port: u16,
     stream: Option<TcpStream>,
     pub session: MarionetteSession