Skip to content

[server] Fix spicedb retry on DEADLINE_EXCEEDED & UNAVAILABLE #20867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions components/server/src/authorization/spicedb-authorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SpiceDBAuthorizer {
const timer = spicedbClientLatency.startTimer();
let error: Error | undefined;
try {
const response = await this.call("[spicedb] Failed to perform authorization check.", (client) =>
const response = await this.call("[spicedb] Error performing authorization check.", (client) =>
client.checkPermission(req, this.callOptions),
);
const permitted = response.permissionship === v1.CheckPermissionResponse_Permissionship.HAS_PERMISSION;
Expand Down Expand Up @@ -185,14 +185,15 @@ export class SpiceDBAuthorizer {
private async call<T>(description: string, code: (client: v1.ZedPromiseClientInterface) => Promise<T>): Promise<T> {
const MAX_ATTEMPTS = 3;
let attempt = 0;
while (attempt++ < 3) {
while (attempt++ < MAX_ATTEMPTS) {
try {
const checkClient = attempt > 1; // the last client error'd out, so check if we should get a new one
const client = this.clientProvider.getClient(checkClient);
return code(client);
return await code(client);
} catch (err) {
// 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
if (
isGrpcError(err) &&
(err.code === grpc.status.DEADLINE_EXCEEDED || err.code === grpc.status.UNAVAILABLE) &&
attempt < MAX_ATTEMPTS
) {
Expand Down
Loading