From 2a4371503495ac82582a6b59e1869c787dadeec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=98=8A?= <414322153@qq.com> Date: Wed, 15 Feb 2023 21:32:49 +0800 Subject: [PATCH] Fixed deadlock when thorw 'EtcdInvalidAuthTokenError' --- src/connection-pool.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/connection-pool.ts b/src/connection-pool.ts index 22e1d6f..3854073 100644 --- a/src/connection-pool.ts +++ b/src/connection-pool.ts @@ -9,14 +9,14 @@ import { IDefaultPolicyContext, IPolicy, isBrokenCircuitError, - Policy, + Policy } from 'cockatiel'; import { castGrpcError, ClientClosedError, ClientRuntimeError, EtcdInvalidAuthTokenError, - isRecoverableError, + isRecoverableError } from './errors'; import { IOptions } from './options'; import { CallContext, ICallable, Services } from './rpc'; @@ -318,11 +318,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; } @@ -331,6 +326,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.