Skip to content

Commit

Permalink
feat: Retry Socket Connection Timeouts on Node 20+ (#2187)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbankhead committed May 2, 2023
1 parent 160aae0 commit 733b560
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ export const RETRYABLE_ERR_FN_DEFAULT = function (err?: ApiError) {
reason.includes('eai_again') || // DNS lookup error
reason === 'econnreset' ||
reason === 'unexpected connection closure' ||
reason === 'epipe'
reason === 'epipe' ||
reason === 'socket connection timeout'
);
};

Expand Down
18 changes: 18 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@ describe('Storage', () => {
assert.strictEqual(calledWith.retryOptions.retryableErrorFn(error), true);
});

it('should retry a socket connection timeout', () => {
const storage = new Storage({
projectId: PROJECT_ID,
});
const calledWith = storage.calledWith_[0];
const error = new ApiError('Broken pipe');
const innerError = {
/**
* @link https://nodejs.org/api/errors.html#err_socket_connection_timeout
* @link https://github.com/nodejs/node/blob/798db3c92a9b9c9f991eed59ce91e9974c052bc9/lib/internal/errors.js#L1570-L1571
*/
reason: 'Socket connection timeout',
};

error.errors = [innerError];
assert.strictEqual(calledWith.retryOptions.retryableErrorFn(error), true);
});

it('should not retry a 999 error', () => {
const storage = new Storage({
projectId: PROJECT_ID,
Expand Down

0 comments on commit 733b560

Please sign in to comment.