Bug 1387403 - Force quitting the browser if no session can be established. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 17 Aug 2017 14:05:11 +0200
changeset 648269 8dd69dd18bf18df418e8b6674c7c91364c306bcd
parent 648260 04bee69b3274bd8d5cf52d54a0a5cc14dbe8693a
child 726757 fcd85e7b462c24331cd057cac010428405901686
push id74680
push userbmo:hskupin@gmail.com
push dateThu, 17 Aug 2017 13:26:18 +0000
bugs1387403
milestone57.0a1
Bug 1387403 - Force quitting the browser if no session can be established. In case the NewSession command fails due to errors returned by Marionette, the browser has to be killed. This is necessary because DeleteSession always requires an existent session, and would fail in closing the browser. So the process would continue to be alive. MozReview-Commit-ID: 1llX4lPNYjN
testing/geckodriver/CHANGES.md
testing/geckodriver/src/marionette.rs
--- a/testing/geckodriver/CHANGES.md
+++ b/testing/geckodriver/CHANGES.md
@@ -10,16 +10,17 @@ All notable changes to this program is d
 
 [`FullscreenWindow`]: https://docs.rs/webdriver/0.29.0/webdriver/command/enum.WebDriverCommand.html#variant.FullscreenWindow
 [`GetWindowRect`]: https://docs.rs/webdriver/0.29.0/webdriver/command/enum.WebDriverCommand.html#variant.GetWindowRect
 [`MaximizeWindow`]: https://docs.rs/webdriver/0.29.0/webdriver/command/enum.WebDriverCommand.html#variant.MaximizeWindow
 [`MinimizeWindow`]: https://docs.rs/webdriver/0.29.0/webdriver/command/enum.WebDriverCommand.html#variant.MinimizeWindow
 [`SetWindowRect`]: https://docs.rs/webdriver/0.29.0/webdriver/command/enum.WebDriverCommand.html#variant.SetWindowRect
 
 ### Changed
+- To make sure no browser process is left behind when the [`New Session` command](https://docs.rs/webdriver/0.27.0/webdriver/command/enum.WebDriverCommand.html#variant.NewSession) fails, the process is closed immediately now.
 - The `proxyType` `noproxy` has been replaced with `direct` in accordance with recent WebDriver specification changes
 - `/moz/addon/install` command accepts an `addon` parameter, in lieu of `path`, containing an addon as a Base64 string
 
 ## 0.18.0 (2017-07-10)
 
 ### Changed
 - [`RectResponse`](https://docs.rs/webdriver/0.27.0/webdriver/response/struct.RectResponse.html) permits returning floats for `width` and `height` fields
 - New type [`CookieResponse`](https://docs.rs/webdriver/0.27.0/webdriver/response/struct.CookieResponse.html) for the [`GetNamedCookie` command](https://docs.rs/webdriver/0.27.0/webdriver/command/enum.WebDriverCommand.html#variant.GetNamedCookie) returns a single cookie, as opposed to an array of a single cookie
--- a/testing/geckodriver/src/marionette.rs
+++ b/testing/geckodriver/src/marionette.rs
@@ -543,17 +543,26 @@ impl WebDriverHandler<GeckoExtensionRout
                 resolved_capabilities = Some(try!(
                     self.create_connection(&msg.session_id, &capabilities)));
             }
         }
 
         match self.connection.lock() {
             Ok(ref mut connection) => {
                 match connection.as_mut() {
-                    Some(conn) => conn.send_command(resolved_capabilities, &msg),
+                    Some(conn) => {
+                        conn.send_command(resolved_capabilities, &msg)
+                            .map_err(|mut err| {
+                                // Shutdown the browser if no session can
+                                // be established due to errors.
+                                if let NewSession(_) = msg.command {
+                                    err.delete_session=true;
+                                }
+                                err})
+                    },
                     None => panic!("Connection missing")
                 }
             },
             Err(_) => {
                 Err(WebDriverError::new(
                     ErrorStatus::UnknownError,
                     "Failed to aquire Marionette connection"))
             }