Skip to content

Commit 733b560

Browse files
authored
feat: Retry Socket Connection Timeouts on Node 20+ (#2187)
1 parent 160aae0 commit 733b560

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/storage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ export const RETRYABLE_ERR_FN_DEFAULT = function (err?: ApiError) {
270270
reason.includes('eai_again') || // DNS lookup error
271271
reason === 'econnreset' ||
272272
reason === 'unexpected connection closure' ||
273-
reason === 'epipe'
273+
reason === 'epipe' ||
274+
reason === 'socket connection timeout'
274275
);
275276
};
276277

test/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,24 @@ describe('Storage', () => {
323323
assert.strictEqual(calledWith.retryOptions.retryableErrorFn(error), true);
324324
});
325325

326+
it('should retry a socket connection timeout', () => {
327+
const storage = new Storage({
328+
projectId: PROJECT_ID,
329+
});
330+
const calledWith = storage.calledWith_[0];
331+
const error = new ApiError('Broken pipe');
332+
const innerError = {
333+
/**
334+
* @link https://nodejs.org/api/errors.html#err_socket_connection_timeout
335+
* @link https://github.com/nodejs/node/blob/798db3c92a9b9c9f991eed59ce91e9974c052bc9/lib/internal/errors.js#L1570-L1571
336+
*/
337+
reason: 'Socket connection timeout',
338+
};
339+
340+
error.errors = [innerError];
341+
assert.strictEqual(calledWith.retryOptions.retryableErrorFn(error), true);
342+
});
343+
326344
it('should not retry a 999 error', () => {
327345
const storage = new Storage({
328346
projectId: PROJECT_ID,

0 commit comments

Comments
 (0)