Skip to content

Commit

Permalink
add retry and shorter individual timeout when fetching plugins
Browse files Browse the repository at this point in the history
Summary: The old approach did a single request with along 30 second timeout., instead we retry multiple times but preserve the same overall timeout

Reviewed By: lblasa

Differential Revision: D57388179

fbshipit-source-id: 1875e73eed322538f74f4b7366e01e1f2bed1620
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed May 16, 2024
1 parent c432ad4 commit f049151
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion desktop/flipper-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"metro-runtime": "^0.70.2",
"pretty-format": "^29.7.0",
"react-refresh": "^0.14.0",
"redux-mock-store": "^1.0.1"
"redux-mock-store": "^1.0.1",
"ts-retry-promise": "^0.8.0"
},
"peerDependencies": {},
"scripts": {
Expand Down
25 changes: 21 additions & 4 deletions desktop/flipper-ui/src/Client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {EventEmitter} from 'eventemitter3';
import {createServerAddOnControls} from './utils/createServerAddOnControls';
import isProduction from './utils/isProduction';
import {freeze} from 'immer';
import {retry} from 'ts-retry-promise';

type Plugins = Set<string>;
type PluginsArr = Array<string>;
Expand Down Expand Up @@ -236,10 +237,26 @@ export default class Client extends EventEmitter {
// get the supported plugins
async loadPlugins(phase: 'init' | 'refresh'): Promise<Set<string>> {
try {
const response = await timeout(
30 * 1000,
this.rawCall<{plugins: Plugins}>('getPlugins', false),
'Fetch plugin timeout. Unresponsive client?',
const response = await retry(
() =>
//shortish timeout for each individual request
timeout(
5 * 1000,
this.rawCall<{plugins: Plugins}>('getPlugins', false),
'Fetch plugin timeout. Unresponsive client?',
),
{
retries: 5,
delay: 1000,
backoff: 'LINEAR',
logger: (msg) =>
this.flipperServer.exec(
'log-connectivity-event',
'warning',
this.query,
`Attempt to fetch plugins failed for phase ${phase}, Error: ${msg}`,
),
},
);
this.plugins = new Set(response.plugins ?? []);
console.info(
Expand Down
5 changes: 5 additions & 0 deletions desktop/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12401,6 +12401,11 @@ ts-node@^10.9.1:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

ts-retry-promise@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/ts-retry-promise/-/ts-retry-promise-0.8.0.tgz#0a0c57b510827d5630da4b0c47f36b55b83a49e3"
integrity sha512-elI/GkojPANBikPaMWQnk4T/bOJ6tq/hqXyQRmhfC9PAD6MoHmXIXK7KilJrlpx47VAKCGcmBrTeK5dHk6YAYg==

tsconfig-paths@^3.15.0:
version "3.15.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz#5299ec605e55b1abb23ec939ef15edaf483070d4"
Expand Down

0 comments on commit f049151

Please sign in to comment.