Skip to content

Commit

Permalink
Merge pull request #407 from ydb-platform/call-cancelled-bug3
Browse files Browse the repository at this point in the history
fix Call cancelled error
  • Loading branch information
Alexey Zorkaltsev authored Sep 26, 2024
2 parents 2da21af + ee14b9f commit 3129356
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/e2e/query-service/query-service-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {

Expand Down
12 changes: 9 additions & 3 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/retries/retryStrategy.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<T>;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/retries_obsoleted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -56,6 +55,7 @@ const RETRYABLE_ERRORS_FAST = [
errors.NotFound,
errors.TransportUnavailable,
errors.ClientDeadlineExceeded,
errors.ClientCancelled,
];
const RETRYABLE_ERRORS_SLOW = [errors.Overloaded, errors.ClientResourceExhausted];

Expand Down

0 comments on commit 3129356

Please sign in to comment.