Http Clients Pools Handling #2773
Answered
by
metcoder95
shalevamit9
asked this question in
Q&A
-
I see in npm docs and GitHub as well the common methods like:
The question is, for example the simple example of: const { request } = require('undici')
async function getRequest (port = 3001) {
// A simple GET request
const {
statusCode,
headers,
body
} = await request(`http://localhost:${port}/`)
const data = await body.text()
console.log('response received', statusCode)
console.log('headers', headers)
console.log('data', data)
}
|
Beta Was this translation helpful? Give feedback.
Answered by
metcoder95
Feb 18, 2024
Replies: 1 comment 2 replies
-
👋
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, that approach is correct and the only way to sort that out for the moment. If the DNS changes and the IP comes with it,
undici
will just fail because the connection might be dropped or not available anymore. Then a new reconnect will be necessary.As you suggest, you can lower the
keepAliveMaxTimeout
to reduce the life of the connection and drop it faster (https://undici.nodejs.org/#/docs/api/Client?id=parameter-clientoptions), if you want to have a faster cycle to minimize this possibility.