Bug 1388251 - Cancel connection attempts if process is not running. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 31 Aug 2017 15:43:20 +0200
changeset 663083 a2440dd71bb0d22105a5ec6f36e6d03014574a2b
parent 662506 fcab453b98651f0d8ad8d342880942a3c435d089
child 663113 a7b04dc9babf0f46e19afbbc37f23e9993e4d4cb
push id79308
push userbmo:hskupin@gmail.com
push dateTue, 12 Sep 2017 15:25:49 +0000
bugs1388251
milestone57.0a1
Bug 1388251 - Cancel connection attempts if process is not running. If the browser process is not running it doesn't make sense to try to connect to it for another 60s. Instead error out immediately. MozReview-Commit-ID: 64DTZfEfzQj
testing/geckodriver/src/marionette.rs
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -423,17 +423,17 @@ impl MarionetteHandler {
         logging::init(&self.current_log_level);
 
         let port = self.settings.port.unwrap_or(try!(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());
+        try!(connection.connect(&mut self.browser));
         self.connection = Mutex::new(Some(connection));
 
         Ok(capabilities)
     }
 
     fn start_browser(&mut self, port: u16, mut options: FirefoxOptions) -> WebDriverResult<()> {
         let binary = try!(options.binary
             .ok_or(WebDriverError::new(ErrorStatus::SessionNotCreated,
@@ -1319,23 +1319,38 @@ impl MarionetteConnection {
     pub fn new(port: u16, session_id: Option<String>) -> MarionetteConnection {
         MarionetteConnection {
             port: port,
             stream: None,
             session: MarionetteSession::new(session_id)
         }
     }
 
-    pub fn connect(&mut self) -> WebDriverResult<()> {
+    pub fn connect(&mut self, browser: &mut Option<FirefoxRunner>) -> WebDriverResult<()> {
         let timeout = 60 * 1000;  // ms
         let poll_interval = 100;  // ms
         let poll_attempts = timeout / poll_interval;
         let mut poll_attempt = 0;
 
         loop {
+            // If the process is gone, immediately abort the connection attempts
+            if let &mut Some(ref mut runner) = browser {
+                let status = runner.status();
+                if status.is_err() || status.as_ref().map(|x| *x).unwrap_or(None) != None {
+                    return Err(WebDriverError::new(
+                        ErrorStatus::UnknownError,
+                        format!("Process unexpectedly closed with status: {}", status
+                            .ok()
+                            .and_then(|x| x)
+                            .and_then(|x| x.code())
+                            .map(|x| x.to_string())
+                            .unwrap_or("{unknown}".into()))));
+                }
+            }
+
             match TcpStream::connect(&(DEFAULT_HOST, self.port)) {
                 Ok(stream) => {
                     self.stream = Some(stream);
                     break
                 },
                 Err(e) => {
                     trace!("  connection attempt {}/{}", poll_attempt, poll_attempts);
                     if poll_attempt <= poll_attempts {