ky: regression: ky aborting in 1.8.0
When using options ky seems to abort, provide no return and wont process any further requests.
example:
import HttpRequestMock from "http-request-mock";
import ky from "ky";
const mockHttp = HttpRequestMock.setupForFetch();
mockHttp.post("https://api.site.test/call", {
data: { payload: "testing" },
});
async function test() {
const test1 = await ky.post(`https://api.site.test/call`, {
json: { testBody: "test" },
});
console.log("test1", test1);
// const test2 = await ky.post(`https://api.site.test/call`);
// console.log("test2:", test2);
}
test()
.then(() => {
process.exit(0);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
Scenarios:
- when running test1 alone, no return, seem to just skip
- when running test1 and test2, no return, both skip
- when running test2 alone, returns as expected
if I comment this out, all scenarios work https://github.com/sindresorhus/ky/blob/main/source/core/Ky.ts#L70-L72
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 22 (2 by maintainers)
Fair enough. Maybe the README and engine section should be updated as well to communicate that more clearly.
The bug seems to be in this code: https://github.com/sindresorhus/ky/compare/v1.7.5...v1.8.1#diff-1d28e040cea335f5a22aa9c3f678f5d00b353e3ce966dc0978a91fe56f240b04R89-R91, it seems to cancel the request body stream before it is even sent…
Tested using the code supplied by @naveen-github above. Commenting out these lines of code fixes the issue, but obviously will fail to cleanup the stream in the cases where it is needed to cancel it.
@sindresorhus @sholladay