-
Notifications
You must be signed in to change notification settings - Fork 559
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
Body timeout not working #3297
Comments
Can you please include a server as well in your example? Otherwise reproducing it is network dependent. |
See the example below. const fs = require('node:fs');
const { pipeline } = require('node:stream/promises');
const http = require('node:http');
const { request } = require('undici');
const server = http.createServer((req, res) => {
res.writeHead(200);
setTimeout(() => {
res.end();
console.log('Request closed after 10 seconds');
}, 10000);
const writeZeroes = () => {
res.write(Buffer.alloc(1024, 0));
setImmediate(writeZeroes);
};
writeZeroes();
});
server.listen();
const serverUrl = `http://localhost:${server.address().port}`;
console.log(`Server listening on ${serverUrl}`);
async function test() {
const { body } = await request(serverUrl, {
throwOnError: true,
bodyTimeout: 1000,
});
console.log('Reading body...');
await pipeline(body, fs.createWriteStream('/tmp/body-timeout-test'));
console.log('Reading body finished');
}
test(); Output:
Reading the response body should timeout after 1 second, but it does not. |
If I'm not mistaken, the e.g. if I alter your example like this: const fs = require('node:fs')
const { pipeline } = require('node:stream/promises')
const http = require('node:http')
const { request } = require('undici')
const server = http.createServer((req, res) => {
res.writeHead(200)
setTimeout(() => {
res.end()
console.log('Request closed after 10 seconds')
}, 10000).unref()
const writeZeroes = () => {
res.write(Buffer.alloc(1024, 0))
setInterval(writeZeroes, 2000)
}
writeZeroes()
})
server.listen(0, () => {
const serverUrl = `http://localhost:${server.address().port}`
console.log(`Server listening on ${serverUrl}`)
async function test () {
console.log('Sending request...')
const { body } = await request(serverUrl, {
throwOnError: true,
bodyTimeout: 1000
})
console.log('Reading body...')
await pipeline(body, fs.createWriteStream('/tmp/body-timeout-test'))
console.log('Reading body finished')
}
test()
}) Then the timeout will effectively apply. You can use |
Thank you, we will try the AbortSignal, but I think the documentation is a bit misleading:
Based on this, I would expect the request to be aborted after the timeout. |
See what you mean, a PR to support us improving the docs is always welcomed! |
Bug Description
Our request below should fail on 'BodyTimeoutError', instead it seems to be an infinite timeout.
It happens mostly with
bodyTimeout
params higher than 500ms.There is an example URL, in the code bellow, but it also happens with others.
Reproducible By
Run this code:
Expected Behavior
Expecting BodyTimeoutError after 1000ms
Environment
The text was updated successfully, but these errors were encountered: