ClientBase should call "stop" if "before_starting_server" failed (#813)

diff --git a/mobly/snippet/client_base.py b/mobly/snippet/client_base.py
index 44ad72f..9954c1d 100644
--- a/mobly/snippet/client_base.py
+++ b/mobly/snippet/client_base.py
@@ -101,6 +101,9 @@
       2. starting the snippet server on the remote device.
       3. making a connection to the snippet server.
 
+    If error occurs at any stage, this function will abort the initialization
+    process and call `stop` to clean up.
+
     Raises:
       errors.ProtocolError: something went wrong when exchanging data with the
         server.
@@ -116,10 +119,11 @@
     self.log.info('Initializing the snippet package %s.', self.package)
     start_time = time.perf_counter()
 
-    self.log.debug('Preparing to start the snippet server of %s.', self.package)
-    self.before_starting_server()
-
     try:
+      self.log.debug('Preparing to start the snippet server of %s.',
+                     self.package)
+      self.before_starting_server()
+
       self.log.debug('Starting the snippet server of %s.', self.package)
       self.start_server()
 
diff --git a/tests/mobly/snippet/client_base_test.py b/tests/mobly/snippet/client_base_test.py
index d9d99bd..e0bc4f1 100755
--- a/tests/mobly/snippet/client_base_test.py
+++ b/tests/mobly/snippet/client_base_test.py
@@ -128,7 +128,7 @@
 
     with self.assertRaisesRegex(Exception, 'ha'):
       self.client.initialize()
-    mock_stop_func.assert_not_called()
+    mock_stop_func.assert_called()
 
   @mock.patch.object(FakeClient, 'stop')
   @mock.patch.object(FakeClient, 'start_server')