From 470c770e97a1f488298603106cee44f151581c5d Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Fri, 21 Dec 2018 07:01:56 -0800 Subject: [PATCH] Back out "[flipper] Explicitly start adb server" Summary: Original commit changeset: b1eae542aaa6 This D13487864 has broken `adb start-server` command for the production builds, thus this diff backs out the changes done by that diff. Reviewed By: danielbuechele Differential Revision: D13532003 fbshipit-source-id: 1d169dcdab11a52f075187803219915f444952d6 --- package.json | 1 + src/dispatcher/androidDevice.js | 38 +++++++++++++++++++++------------ yarn.lock | 18 ++++++++++++++++ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index eecacea65..61be1888d 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "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 ffb905784..da4b8bd4b 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 {promisify} from 'util'; +import promiseRetry from 'promise-retry'; import type {Store} from '../reducers/index.js'; import type BaseDevice from '../devices/BaseDevice'; import type Logger from '../fb-stubs/Logger.js'; @@ -55,21 +55,31 @@ function getRunningEmulatorName(id: string): Promise { } export default (store: Store, logger: Logger) => { - // 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. + // 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. function createClient() { - 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 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, + }, + ); } + const clientPromise = createClient(); const watchAndroidDevices = () => { // get emulators @@ -88,7 +98,7 @@ export default (store: Store, logger: Logger) => { }, ); - createClient() + clientPromise .then(client => { client .trackDevices() diff --git a/yarn.lock b/yarn.lock index 66a58c2ac..6dad39c8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2287,6 +2287,11 @@ 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" @@ -5158,6 +5163,14 @@ 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" @@ -5669,6 +5682,11 @@ 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"