Skip to content

Commit 7d1a8eb

Browse files
authored
[server] Fix spicedb retry on DEADLINE_EXCEEDED & UNAVAILABLE (#20867)
1 parent a6f6de2 commit 7d1a8eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

components/server/src/authorization/spicedb-authorizer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class SpiceDBAuthorizer {
5757
const timer = spicedbClientLatency.startTimer();
5858
let error: Error | undefined;
5959
try {
60-
const response = await this.call("[spicedb] Failed to perform authorization check.", (client) =>
60+
const response = await this.call("[spicedb] Error performing authorization check.", (client) =>
6161
client.checkPermission(req, this.callOptions),
6262
);
6363
const permitted = response.permissionship === v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION;
@@ -185,14 +185,15 @@ export class SpiceDBAuthorizer {
185185
private async call<T>(description: string, code: (client: v1.ZedPromiseClientInterface) => Promise<T>): Promise<T> {
186186
const MAX_ATTEMPTS = 3;
187187
let attempt = 0;
188-
while (attempt++ < 3) {
188+
while (attempt++ < MAX_ATTEMPTS) {
189189
try {
190190
const checkClient = attempt > 1; // the last client error'd out, so check if we should get a new one
191191
const client = this.clientProvider.getClient(checkClient);
192-
return code(client);
192+
return await code(client);
193193
} catch (err) {
194194
// Check: Is this a "no connection to upstream" error? If yes, retry here, to work around grpc/grpc-js bugs introducing high latency for re-tries
195195
if (
196+
isGrpcError(err) &&
196197
(err.code === grpc.status.DEADLINE_EXCEEDED || err.code === grpc.status.UNAVAILABLE) &&
197198
attempt < MAX_ATTEMPTS
198199
) {

0 commit comments

Comments
 (0)