ky icon indicating copy to clipboard operation
ky copied to clipboard

Timeout doesn't behave like documented

Open michal-billtech opened this issue 1 month ago • 3 comments

try {
    await Promise.race([
        new Promise((resolve, reject) => setTimeout(() => reject(new Error("my timeout")), 2000)),
        ky("https://pie.dev/status/429", {
            retry: {
                limit: 15,
            },
            timeout: 1000,
        }),
    ]);
} catch (err: unknown) {
    console.log(err); // Error: my timeout
}

The documentation says:

Timeout in milliseconds for getting a response, including any retries. Can not be greater than 2147483647. If set to false, there will be no timeout.

Reading this, I expected the code above to throw TimeoutError after 1000 ms, but rather it throws "my timeout" after 2000 ms.

What was the real intention here?

michal-billtech avatar Nov 03 '25 15:11 michal-billtech

Hi! I’d like to work on this issue and submit a PR. I can help clarify the behavior of timeout in Ky with Promise.race and provide a minimal example demonstrating the expected behavior. Could you please assign this to me?

KirtiGautam620 avatar Nov 15 '25 17:11 KirtiGautam620

This should be fixed, but it's a breaking change to fix this at this point, so should be done for v2.

sindresorhus avatar Nov 15 '25 19:11 sindresorhus

@KirtiGautam620 Thanks for offering, but I prefer to do the change myself. It's a little bit involved and an outside contribution would take more effort than fixing this ourselves.

sindresorhus avatar Nov 15 '25 19:11 sindresorhus