Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Retry Socket Connection Timeouts on Node 20+ #2187

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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