Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
devil: Try safely handling 'connect for root closed' errors when rooting
Browse files Browse the repository at this point in the history
We're seeing these errors during random `adb root` calls, which ends
up poisoning the rest of the test:
https://chromium-swarm.appspot.com/task?id=4ea8f76daeeb4d10

Hopefully with this extra wait-for-device call, we can let the rest of
the shard proceed safely with the retries of root it attempts.

Bug: chromium:1127009
Change-Id: I52f07394840fa1e5572f10841967e67487e97ce2
Reviewed-on: https://chromium-review.googlesource.com/c/catapult/+/2411339
Reviewed-by: John Budorick <jbudorick@chromium.org>
Commit-Queue: Ben Pastene <bpastene@chromium.org>
  • Loading branch information
bpastene authored and Commit Bot committed Sep 16, 2020
1 parent 2f979a7 commit 4cb0981
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion devil/devil/android/sdk/adb_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,16 @@ def Root(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES):
timeout: (optional) Timeout per try in seconds.
retries: (optional) Number of retries to attempt.
"""
output = self._RunDeviceAdbCmd(['root'], timeout, retries)
try:
output = self._RunDeviceAdbCmd(['root'], timeout, retries)
except device_errors.AdbCommandFailedError as e:
# For some devices, root can occasionally fail with this error and kick
# the device into adb 'offline' mode. Assuming this is transient, try
# waiting for the device to come back up before re-raising the exception
# and proceeding with any retries.
if 'unable to connect for root: closed' in e.output:
self.WaitForDevice()
raise
if 'cannot' in output:
raise device_errors.AdbCommandFailedError(
['root'], output, device_serial=self._device_serial)
Expand Down
9 changes: 9 additions & 0 deletions devil/devil/android/sdk/adb_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ def testWaitingForDevice(self, get_cmd_mock):
get_cmd_mock.return_value = (1, '- waiting for device - ')
self.assertRaises(device_errors.DeviceUnreachableError, self.adb.Shell,
'/bin/true')

@mock.patch('devil.utils.cmd_helper.GetCmdStatusAndOutputWithTimeout')
def testRootConnectionClosedFailure(self, get_cmd_mock):
get_cmd_mock.side_effect = [
(1, 'unable to connect for root: closed'),
(0, ''),
]
self.assertRaises(device_errors.AdbCommandFailedError, self.adb.Root,
retries=0)

0 comments on commit 4cb0981

Please sign in to comment.