Skip to content

Commit 3c53452

Browse files
committed
Improve remote admin client reconnect timings
This sets a max time, making it easier to increase the total retries further, and smooths the initial growth of the exponential delay slightly.
1 parent 96217c9 commit 3c53452

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/client/admin-client.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { MockttpPluginOptions } from '../admin/mockttp-admin-plugin';
2121
import { AdminPlugin, PluginClientResponsesMap, PluginStartParamsMap } from '../admin/admin-plugin-types';
2222
import { SchemaIntrospector } from './schema-introspection';
2323
import { AdminQuery, getSingleSelectedFieldName } from './admin-query';
24-
import { MockttpOptions } from '../mockttp';
2524

2625
const { fetch, Headers } = isNode || typeof globalThis.fetch === 'undefined'
2726
? CrossFetch
@@ -223,7 +222,7 @@ export class AdminClient<Plugins extends { [key: string]: AdminPlugin<any, any>
223222
this.debug = !!options.debug;
224223
this.adminClientOptions = _.defaults(options, {
225224
adminServerUrl: `http://localhost:${DEFAULT_ADMIN_SERVER_PORT}`,
226-
adminStreamReconnectAttempts: 5
225+
adminStreamReconnectAttempts: 8
227226
});
228227
}
229228

@@ -309,9 +308,8 @@ export class AdminClient<Plugins extends { [key: string]: AdminPlugin<any, any>
309308
if (retries > 0) {
310309
// We delay re-retrying briefly - this helps to handle cases like the computer going
311310
// to sleep (where the server & client pause in parallel, but race to do so).
312-
// The delay increases exponentially with retry attempts (10ms, 50, 250, 1250, 6250)
313311
const retryAttempt = this.adminClientOptions.adminStreamReconnectAttempts - retries;
314-
await delay(10 * Math.pow(5, retryAttempt));
312+
await delay(Math.min(25 * Math.pow(2, retryAttempt), 2_000));
315313

316314
return this.tryToReconnectStream(adminSessionBaseUrl, targetStream, retries - 1);
317315
}

0 commit comments

Comments
 (0)