in src/connection-pool.ts [293:343]
public async exec<T>(
serviceName: keyof typeof Services,
method: string,
payload: unknown,
options?: grpc.CallOptions,
): Promise<T> {
if (this.mockImpl) {
return this.mockImpl.exec(serviceName, method, payload);
}
const shuffleGen = this.shuffledHosts();
let lastError: Error | undefined;
try {
return await this.globalPolicy.execute(() =>
this.withConnection(
serviceName,
async ({ client, metadata }) => {
const resolvedOpts = resolveCallOptions(options, this.callOptionsFactory, {
service: serviceName,
method,
params: payload,
isStream: false,
} as CallContext);
try {
return await runServiceCall(client, metadata, resolvedOpts, method, payload);
} catch (err) {
if (err instanceof EtcdInvalidAuthTokenError) {
this.authenticator.invalidateMetadata();
return this.exec(serviceName, method, payload, options);
}
lastError = err;
throw err;
}
},
shuffleGen,
),
);
} catch (e) {
// If we ran into an error that caused the a circuit to open, but we had
// an error before that happened, throw the original error rather than
// the broken circuit error.
if (isBrokenCircuitError(e) && lastError && !isBrokenCircuitError(lastError)) {
throw lastError;
} else {
throw e;
}
}
}