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

fix(transporter): error for too high timeout values #1272

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/transporter/src/createTransporter.ts
Expand Up @@ -9,6 +9,9 @@ import {
} from '.';
import { retryableRequest } from './concerns/retryableRequest';

// setTimeout is using uint32, so this is the maximum in ms and 5x is the max timeout multiplier
const MAX_TIMEOUT_VALUE = 0x7fffffff / 5000;

export function createTransporter(options: TransporterOptions): Transporter {
const {
hostsCache,
Expand All @@ -23,6 +26,16 @@ export function createTransporter(options: TransporterOptions): Transporter {
headers,
} = options;

if (
timeouts.connect > MAX_TIMEOUT_VALUE ||
timeouts.read > MAX_TIMEOUT_VALUE ||
timeouts.write > MAX_TIMEOUT_VALUE
) {
throw new Error(
`Timeout values can be no higher than setTimeout accepts (in seconds), ${MAX_TIMEOUT_VALUE}`
);
}

const transporter: Transporter = {
hostsCache,
logger,
Expand Down