From ee14b9f386059a97b41ebe417fab905ea72b18ba Mon Sep 17 00:00:00 2001 From: Alexey Zorkaltsev Date: Thu, 26 Sep 2024 18:22:22 +0300 Subject: [PATCH] fix: "Call cancelled" error To make the retrier triggered by a "Call canceled" error you should use tableClient.withSessionRetry instead of tableClient.withSession --- .../e2e/query-service/query-service-client.ts | 2 +- src/errors.ts | 12 +++++++++--- src/retries/retryStrategy.ts | 4 ++-- src/retries_obsoleted.ts | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/__tests__/e2e/query-service/query-service-client.ts b/src/__tests__/e2e/query-service/query-service-client.ts index 9d2936d1..76a8a759 100644 --- a/src/__tests__/e2e/query-service/query-service-client.ts +++ b/src/__tests__/e2e/query-service/query-service-client.ts @@ -9,7 +9,7 @@ import {QuerySession, IExecuteResult} from "../../../query"; if (process.env.TEST_ENVIRONMENT === 'dev') require('dotenv').config(); const DATABASE = '/local'; -const ENDPOINT = process.env.YDB_ENDPOINT || 'grpc://localhost:2135'; +const ENDPOINT = process.env.YDB_ENDPOINT || 'grpc://localhost:2136'; describe('Query client', () => { diff --git a/src/errors.ts b/src/errors.ts index 92137d07..e185589c 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -46,6 +46,7 @@ export enum StatusCode { UNAUTHENTICATED = CLIENT_STATUSES_FIRST + 30, // SDK local SESSION_POOL_EMPTY = CLIENT_STATUSES_FIRST + 40, // SDK local + RETRIES_EXCEEDED = CLIENT_STATUSES_FIRST + 50, // SDK local } /** @@ -314,15 +315,20 @@ export class ClientResourceExhausted extends TransportError { public readonly [RetryPolicySymbol] = retryPolicy(Backoff.Slow, false, true, true); } +export class ClientCancelled extends TransportError { + static status = StatusCode.CLIENT_CANCELED; + public readonly [RetryPolicySymbol] = retryPolicy(Backoff.No, false, false, false); +} + const TRANSPORT_ERROR_CODES = new Map([ - [GrpcStatus.CANCELLED, Cancelled], + [GrpcStatus.CANCELLED, ClientCancelled], [GrpcStatus.UNAVAILABLE, TransportUnavailable], [GrpcStatus.DEADLINE_EXCEEDED, ClientDeadlineExceeded], [GrpcStatus.RESOURCE_EXHAUSTED, ClientResourceExhausted] ]); -export class ClientCancelled extends YdbError { - static status = StatusCode.CLIENT_CANCELED; +export class RetriesExceeded extends YdbError { + static status = StatusCode.RETRIES_EXCEEDED; public readonly [RetryPolicySymbol] = retryPolicy(Backoff.No, false, false, false); constructor(public readonly cause: Error) { diff --git a/src/retries/retryStrategy.ts b/src/retries/retryStrategy.ts index 520a5e7b..26d792a4 100644 --- a/src/retries/retryStrategy.ts +++ b/src/retries/retryStrategy.ts @@ -1,4 +1,4 @@ -import {Backoff, ClientCancelled, SpecificErrorRetryPolicy} from "../errors"; +import {Backoff, RetriesExceeded, SpecificErrorRetryPolicy} from "../errors"; import {HasLogger} from "../logger/has-logger"; import {Logger} from "../logger/simple-logger"; import {RetryParameters} from "./retryParameters"; @@ -45,7 +45,7 @@ export class RetryStrategy implements HasLogger { while (true) { if (maxRetries !== 0 && attemptsCounter >= maxRetries) { // to support the old logic for a while this.logger.debug(tooManyAttempts, attemptsCounter); - throw new ClientCancelled(new Error(`Too many attempts: ${attemptsCounter}`)); + throw new RetriesExceeded(new Error(`Too many attempts: ${attemptsCounter}`)); } let r: RetryLambdaResult; try { diff --git a/src/retries_obsoleted.ts b/src/retries_obsoleted.ts index d27de982..2f1a3486 100644 --- a/src/retries_obsoleted.ts +++ b/src/retries_obsoleted.ts @@ -2,7 +2,6 @@ import {YdbError, TransportError} from './errors'; import * as errors from './errors'; import * as utils from "./utils"; import {Logger} from "./logger/simple-logger"; -// import {getDefaultLogger} from "./logger/get-default-logger"; export class BackoffSettings { /** @@ -56,6 +55,7 @@ const RETRYABLE_ERRORS_FAST = [ errors.NotFound, errors.TransportUnavailable, errors.ClientDeadlineExceeded, + errors.ClientCancelled, ]; const RETRYABLE_ERRORS_SLOW = [errors.Overloaded, errors.ClientResourceExhausted];