diff --git a/src/connection-pool.ts b/src/connection-pool.ts index d24de00..f800195 100644 --- a/src/connection-pool.ts +++ b/src/connection-pool.ts @@ -11,6 +11,7 @@ import { IDefaultPolicyContext, IPolicy, isBrokenCircuitError, + Policy retry, } from 'cockatiel'; import { @@ -18,7 +19,7 @@ import { ClientClosedError, ClientRuntimeError, EtcdInvalidAuthTokenError, - isRecoverableError, + isRecoverableError } from './errors'; import { IOptions } from './options'; import { CallContext, ICallable, Services } from './rpc'; @@ -323,11 +324,6 @@ export class ConnectionPool implements ICallable { 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; } @@ -336,6 +332,13 @@ export class ConnectionPool implements ICallable { ), ); } catch (e) { + + // Tf auth token error, clear metadata and retry + if (e instanceof EtcdInvalidAuthTokenError) { + this.authenticator.invalidateMetadata(); + return this.exec(serviceName, method, payload, options); + } + // 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.