From cc5fba69753b0aef141d0b332017c7a9db3513bd Mon Sep 17 00:00:00 2001 From: John Knox Date: Mon, 17 Dec 2018 07:39:32 -0800 Subject: [PATCH] Explicitly start adb server Summary: We were relying on adbkit to do this, implicitly by calling listDevices(). However, this doesn't appear to be reliable, with retries, it usually succeeds, but sometimes still doesn't. I'm aiming to avoid all this entirely by just starting it directly using adb itself, which I expect to be much more reliable. Reviewed By: danielbuechele Differential Revision: D13487864 fbshipit-source-id: b1eae542aaa6ecb2b74b575a3582934093ccd588 --- package.json | 1 - src/dispatcher/androidDevice.js | 38 ++++++++++++--------------------- yarn.lock | 18 ---------------- 3 files changed, 14 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 94bfa6efa..ce60e846e 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "lodash.debounce": "^4.0.8", "mkdirp": "^0.5.1", "openssl-wrapper": "^0.3.4", - "promise-retry": "^1.1.1", "prop-types": "^15.6.0", "react": "16", "react-color": "^2.11.7", diff --git a/src/dispatcher/androidDevice.js b/src/dispatcher/androidDevice.js index da4b8bd4b..ffb905784 100644 --- a/src/dispatcher/androidDevice.js +++ b/src/dispatcher/androidDevice.js @@ -7,7 +7,7 @@ import AndroidDevice from '../devices/AndroidDevice'; import child_process from 'child_process'; -import promiseRetry from 'promise-retry'; +import {promisify} from 'util'; import type {Store} from '../reducers/index.js'; import type BaseDevice from '../devices/BaseDevice'; import type Logger from '../fb-stubs/Logger.js'; @@ -55,31 +55,21 @@ function getRunningEmulatorName(id: string): Promise { } export default (store: Store, logger: Logger) => { - // Using this client before adb server is started up will cause failures. - // this gets around this by waiting for listDevices first, which ensures - // the server is up and running before allowing any other operations. + // Adbkit will attempt to start the adb server if it's not already running, + // however, it sometimes fails with ENOENT errors. So instead, we start it + // manually before requesting a client. function createClient() { - const unsafeClient = adb.createClient(); - return promiseRetry( - (retry, number) => { - return unsafeClient - .listDevices() - .then(() => { - return unsafeClient; - }) - .catch(e => { - console.warn(`Failed to start adb client. Retrying. ${e.message}`); - retry(e); - }); - }, - { - minTimeout: 200, - retries: 5, - }, - ); + return promisify(child_process.exec)('adb start-server') + .then(result => { + if (result.error) { + throw new Error( + `Failed to start adb server: ${result.stderr.toString()}`, + ); + } + }) + .then(adb.createClient); } - const clientPromise = createClient(); const watchAndroidDevices = () => { // get emulators @@ -98,7 +88,7 @@ export default (store: Store, logger: Logger) => { }, ); - clientPromise + createClient() .then(client => { client .trackDevices() diff --git a/yarn.lock b/yarn.lock index 5b6b316c2..f7bcddc43 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2280,11 +2280,6 @@ env-paths@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0" -err-code@^1.0.0: - version "1.1.2" - resolved "https://registry.yarnpkg.com/err-code/-/err-code-1.1.2.tgz#06e0116d3028f6aef4806849eb0ea6a748ae6960" - integrity sha1-BuARbTAo9q70gGhJ6w6mp0iuaWA= - error-ex@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc" @@ -5149,14 +5144,6 @@ progress@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.0.tgz#8a1be366bf8fc23db2bd23f10c6fe920b4389d1f" -promise-retry@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/promise-retry/-/promise-retry-1.1.1.tgz#6739e968e3051da20ce6497fb2b50f6911df3d6d" - integrity sha1-ZznpaOMFHaIM5kl/srUPaRHfPW0= - dependencies: - err-code "^1.0.0" - retry "^0.10.0" - promise@^7.1.1: version "7.3.1" resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf" @@ -5653,11 +5640,6 @@ ret@~0.1.10: resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg== -retry@^0.10.0: - version "0.10.1" - resolved "https://registry.yarnpkg.com/retry/-/retry-0.10.1.tgz#e76388d217992c252750241d3d3956fed98d8ff4" - integrity sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q= - rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1: version "2.6.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"