diff --git a/packages/transporter/src/createTransporter.ts b/packages/transporter/src/createTransporter.ts index 278cf225e..8a14126a7 100644 --- a/packages/transporter/src/createTransporter.ts +++ b/packages/transporter/src/createTransporter.ts @@ -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, @@ -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,