Cannot make Pool working with client factory #3373
Answered
by
ronag
evgeny-kim
asked this question in
Q&A
-
I'm creating a pool of clients with a pre-built retry interceptor. Such pool only makes one request per connection, a total of 3 requests in the below example. All subsequent requests are queued and never get sent. Without factory everything works perfect. What am I doing wrong? import { Client, Pool, interceptors } from 'undici';
const test = () => {
const createRetryClient = (origin, opts) => {
return new Client(origin, opts).compose(
interceptors.retry({ maxRetries: 3 })
);
}
const pool = new Pool(
'https://httpbin.org',
{
connections: 3,
factory: createRetryClient
}
)
const request = async (id) => {
const { body } = await pool.request({
path: '/headers',
method: 'GET'
});
const data = await body.json();
console.log(
id,
data.headers['Host'],
`Connected: ${pool.stats.connected}`,
`Queued: ${pool.stats.queued}`,
`Running: ${pool.stats.running}`
);
}
for (let i = 0; i < 10; i++) {
request(i);
}
}
test(); |
Beta Was this translation helpful? Give feedback.
Answered by
ronag
Jun 25, 2024
Replies: 1 comment 1 reply
Answer selected by
evgeny-kim
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#3368