-
Notifications
You must be signed in to change notification settings - Fork 567
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
headersTimeout on Agent appears to be broken since 6.20.0 #3798
Comments
Du you have a full repro? |
|
The behaviour is indeed changed, I couldn't reproduce it your code in isolation; but I was able to figure out that this might has to be something with the work done for the fast timers. As, if e.g. For instance, my guess is that maybe mocha does something with timers that messes the fast timers implementation and causes undici to drift some the expected behaviour. import { createServer } from 'node:http'
import { once } from 'node:events'
import { Agent, fetch } from './index.js' // main & v6.x behaves the same
const app = createServer((req, res) => {
setTimeout(() => {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('hello world')
}, 10) // Change to 500 or 1000 to cause a UND_ERR_HEADERS_TIMEOUT
})
app.listen(0)
await once(app, 'listening')
const dispatcher = new Agent({
connectTimeout: 1,
bodyTimeout: 1,
headersTimeout: 1
})
const result = await fetch(`http://127.0.0.1:${app.address().port}/delayed`, {
redirect: 'manual',
headers: { accept: 'text/plain' },
method: 'GET',
keepalive: true,
dispatcher
})
console.log(result.status, await result?.text())
|
@metcoder95 sorry for the ridiculously long delay getting back to you.... honestly i pinned undici and forgot about it :| I'm now trying to upgrade and running into this again, I've actually realised the reason my mocha tests were failing is because they had a See this example code:
This does throw On |
Maybe we should change the resolution of the fast timers? |
I suppose the question really is how much it matters. For my particular use case, not so much. However you could argue for someone who had these settings configured low to "fail fast", it's somewhat of an unexpected breaking change in a minor release. But I don't know the broader intent/expectation of these config options for the project or the trade offs that come with making them more accurate. |
Indeed here the question will be a matter of tradeoffs. Such low timeout is not something common outside of testing, and given that no much issues has been raised around that; maybe the value of changing the resolution agains the value added might not be well amortized. I'd suggest that, unless this brings more troubles in actual production-like workloads; we should keep it as is for the time being. |
I do believe it should at least be documented, perhaps also on the jsdoc for those config items to let people know about the resolution. |
Good call, would you like to send a PR for that? |
I think it's better written by somebody who understands the timer implementation and the intent of the change. |
Bug Description
Using
fetch
with anundici
agent with configuration such asnew Agent({ headersTimeout: 1})
on6.19.8
would correctly throw aUND_ERR_HEADERS_TIMEOUT
error whereas on6.20.0
and6.20.1
the request just hangs.This was caught by some tests we have around our http client that ensures timeouts work, and they started failing after the
undici
bump.Reproducible By
As above really.
Expected Behavior
UND_ERR_HEADERS_TIMEOUT
to throw on a headers timeout.Logs & Screenshots
Environment
node v22.5.1
undici v6.20.x
Additional context
The text was updated successfully, but these errors were encountered: