Skip to content

Commit

Permalink
fix(transporter): error for too high timeout values
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed May 21, 2021
1 parent 84355a9 commit 142d5e2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/transporter/src/createTransporter.ts
Original file line number Diff line number Diff line change
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

0 comments on commit 142d5e2

Please sign in to comment.