Bug 1461608 - [geckodriver] Reduce stream read timeout for Marionette handshake to 10s. r=ato
authorHenrik Skupin <mail@hskupin.info>
Mon, 03 Sep 2018 16:40:08 +0200
changeset 434742 492491501281e4c9b8d7db0f1584171420a20989
parent 434741 082161ea398a4400cc911abf61749e2df1c736be
child 434743 e99f9ea180465aacbe10bca19201d54a2919e29f
push id107479
push userhskupin@mozilla.com
push dateWed, 05 Sep 2018 07:09:55 +0000
treeherdermozilla-inbound@492491501281 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1461608
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1461608 - [geckodriver] Reduce stream read timeout for Marionette handshake to 10s. r=ato By default the stream read timeout is set to None, which means if geckodriver successfully connects to a port, which doesn't send any data, it waits forever. Given that handshake data should be received immediately reduce the read timeout on supported platforms to 10s. This would still allow slower builds (eg. ASAN) to send the Marionette handshake.
testing/geckodriver/src/marionette.rs
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -1113,26 +1113,52 @@ impl MarionetteConnection {
                             ErrorStatus::UnknownError,
                             e.description().to_owned(),
                         ));
                     }
                 }
             }
         }
 
+        debug!(
+            "Connection established on {}:{}. Waiting for Marionette handshake",
+            DEFAULT_HOST, self.port,
+        );
+
         let data = self.handshake()?;
         self.session.application_type = Some(data.application_type);
         self.session.protocol = Some(data.protocol);
 
-        debug!("Connected to Marionette on {}:{}", DEFAULT_HOST, self.port);
+        debug!("Connected to Marionette");
         Ok(())
     }
 
     fn handshake(&mut self) -> WebDriverResult<MarionetteHandshake> {
-        let resp = self.read_resp()?;
+        let resp = (match self.stream.as_mut().unwrap().read_timeout() {
+            Ok(timeout) => {
+                // If platform supports changing the read timeout of the stream,
+                // use a short one only for the handshake with Marionette.
+                self.stream
+                    .as_mut()
+                    .unwrap()
+                    .set_read_timeout(Some(time::Duration::from_secs(10)))
+                    .ok();
+                let data = self.read_resp();
+                self.stream.as_mut().unwrap().set_read_timeout(timeout).ok();
+
+                data
+            }
+            _ => self.read_resp(),
+        }).or_else(|e| {
+            Err(WebDriverError::new(
+                ErrorStatus::UnknownError,
+                format!("Socket timeout reading Marionette handshake data: {}", e),
+            ))
+        })?;
+
         let data = serde_json::from_str::<MarionetteHandshake>(&resp)?;
 
         if data.application_type != "gecko" {
             return Err(WebDriverError::new(
                 ErrorStatus::UnknownError,
                 format!(
                     "Unrecognized application type {}",
                     data.application_type