Skip to content

Commit 90de80f

Browse files
authored
fix: retry rst_stream errors (#1059)
1 parent 3718011 commit 90de80f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/table.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,19 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
946946

947947
rowStream = pumpify.obj([requestStream, chunkTransformer, toRowStream]);
948948

949+
// Retry on "received rst stream" errors
950+
const isRstStreamError = (error: ServiceError): boolean => {
951+
if (error.code === 13 && error.message) {
952+
const error_message = (error.message || '').toLowerCase();
953+
return (
954+
error.code === 13 &&
955+
(error_message.includes('rst_stream') ||
956+
error_message.includes('rst stream'))
957+
);
958+
}
959+
return false;
960+
};
961+
949962
rowStream
950963
.on('error', (error: ServiceError) => {
951964
rowStream.unpipe(userStream);
@@ -959,7 +972,7 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
959972
numConsecutiveErrors++;
960973
if (
961974
numConsecutiveErrors <= maxRetries &&
962-
RETRYABLE_STATUS_CODES.has(error.code)
975+
(RETRYABLE_STATUS_CODES.has(error.code) || isRstStreamError(error))
963976
) {
964977
const backOffSettings =
965978
options.gaxOptions?.retry?.backoffSettings ||

test/table.ts

+22
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,28 @@ describe('Bigtable/Table', () => {
14291429
done();
14301430
});
14311431
});
1432+
1433+
it('should retry received rst stream errors', done => {
1434+
const rstStreamError = new Error('Received Rst_stream') as ServiceError;
1435+
rstStreamError.code = 13;
1436+
emitters = [
1437+
((stream: Duplex) => {
1438+
stream.emit('error', rstStreamError);
1439+
}) as {} as EventEmitter,
1440+
((stream: Duplex) => {
1441+
stream.end([{key: 'a'}]);
1442+
}) as {} as EventEmitter,
1443+
];
1444+
1445+
const options = {
1446+
keys: ['a'],
1447+
};
1448+
1449+
callCreateReadStream(options, () => {
1450+
assert.strictEqual(reqOptsCalls.length, 2);
1451+
done();
1452+
});
1453+
});
14321454
});
14331455
});
14341456

0 commit comments

Comments
 (0)