Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 6832df7

Browse files
feat: enable retries for RESOURCE_EXHAUSTED an simplify error codes (#1070)
Unify retriable status codes for ReadRows and MutateRows to be DEADLINE_EXCEEDED - RESOURCE_EXHAUSTED, ABORTED, UNAVAILABLE.
1 parent ab0d52b commit 6832df7

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/table.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ import {google} from '../protos/protos';
4444
import {Duplex} from 'stream';
4545

4646
// See protos/google/rpc/code.proto
47-
// (4=DEADLINE_EXCEEDED, 10=ABORTED, 14=UNAVAILABLE)
48-
const RETRYABLE_STATUS_CODES = new Set([4, 10, 14]);
49-
const IDEMPOTENT_RETRYABLE_STATUS_CODES = new Set([4, 14]);
47+
// (4=DEADLINE_EXCEEDED, 8=RESOURCE_EXHAUSTED, 10=ABORTED, 14=UNAVAILABLE)
48+
const RETRYABLE_STATUS_CODES = new Set([4, 8, 10, 14]);
5049
// (1=CANCELLED)
5150
const IGNORED_STATUS_CODES = new Set([1]);
5251

@@ -1564,7 +1563,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
15641563
// If the error is empty but there are still outstanding mutations,
15651564
// it means that there are retryable errors in the mutate response
15661565
// even when the RPC succeeded
1567-
return !err || IDEMPOTENT_RETRYABLE_STATUS_CODES.has(err.code);
1566+
return !err || RETRYABLE_STATUS_CODES.has(err.code);
15681567
};
15691568

15701569
const onBatchResponse = (err: ServiceError | null) => {
@@ -1648,7 +1647,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
16481647
mutationErrorsByEntryIndex.delete(originalEntriesIndex);
16491648
return;
16501649
}
1651-
if (!IDEMPOTENT_RETRYABLE_STATUS_CODES.has(entry.status!.code!)) {
1650+
if (!RETRYABLE_STATUS_CODES.has(entry.status!.code!)) {
16521651
pendingEntryIndices.delete(originalEntriesIndex);
16531652
}
16541653
const errorDetails = entry.status;

test/table.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,8 +2485,8 @@ describe('Bigtable/Table', () => {
24852485
{
24862486
index: 1,
24872487
status: {
2488-
code: 10,
2489-
message: 'ABORTED',
2488+
code: 3,
2489+
message: 'INVALID_ARGUMENT',
24902490
},
24912491
},
24922492
];
@@ -2652,14 +2652,14 @@ describe('Bigtable/Table', () => {
26522652
});
26532653

26542654
describe('rpc level retries', () => {
2655-
let emitters: EventEmitter[] | null; // = [((stream: Writable) => { stream.push([{ key: 'a' }]);
2655+
let emitters: EventEmitter[]; // = [((stream: Writable) => { stream.push([{ key: 'a' }]);
26562656
let requestArgs: RequestOptions[] = [];
26572657

26582658
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26592659
let entryRequests: any;
26602660

26612661
beforeEach(() => {
2662-
emitters = null; // This needs to be assigned in each test case.
2662+
emitters = []; // This needs to be assigned in each test case.
26632663

26642664
requestArgs = [];
26652665
entryRequests = [];
@@ -2682,7 +2682,7 @@ describe('Bigtable/Table', () => {
26822682

26832683
it('should not retry unretriable errors', done => {
26842684
const unretriableError = new Error('not retryable') as ServiceError;
2685-
unretriableError.code = 10; // Aborted
2685+
unretriableError.code = 3; // INVALID_ARGUMENT
26862686
emitters = [
26872687
((stream: Writable) => {
26882688
stream.emit('error', unretriableError);

0 commit comments

Comments
 (0)