undici icon indicating copy to clipboard operation
undici copied to clipboard

ProxyAgent can not work with Pool request

Open suil opened this issue 3 years ago • 8 comments

Bug Description

  const pool = new Pool(url);
  const proxyAgent = new ProxyAgent("http://one-proxy:8080");
  const { statusCode, body } = await pool.request({
    ...
    dispatcher: proxyAgent,
    ...
  ...});

when Pool is used, it's not picking up { ..., dispatcher: new ProxyAgent("...")}, nor setGlobalDispatcher(proxyAgent).

However, request is used, ProxyAgent works.

my code is behind the proxy. also Pool is the one I will need to use.

Reproducible By

Expected Behavior

Logs & Screenshots

{
  error: Error: getaddrinfo ENOTFOUND eth-testnet-communities-152b99c6597fb22e.elb.us-west-2.amazonaws.com
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
      at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'eth-testnet-communities-152b99c6597fb22e.elb.us-west-2.amazonaws.com'
  }
}

Environment

Node v16.14.0

Additional context

suil avatar Mar 10 '22 03:03 suil

This is expected but we likely are not throwing a descriptive error.

mcollina avatar Mar 10 '22 08:03 mcollina

Should we throw an error if dispatcher is passed somewhere where it is not expected?

ronag avatar Mar 10 '22 09:03 ronag

I think so.

mcollina avatar Mar 10 '22 11:03 mcollina

why is this expected? so pool is not suppose to use proxy?

suil avatar Mar 10 '22 17:03 suil

Pool is a group of connections to a single client. A proxy (by its definition) allows to connect to all hosts. You should just use the proxy directly.

mcollina avatar Mar 10 '22 19:03 mcollina

thanks! any example of using proxy directly?

suil avatar Mar 11 '22 16:03 suil

Isn't https://github.com/nodejs/undici/blob/main/examples/proxy-agent.js enough? I think you can also call proxyAgent.request().

mcollina avatar Mar 13 '22 10:03 mcollina

Hardhat plugin uses undici with Pool and has the same problem. It does not work behind corporate proxy.

umakanth-fmr avatar Sep 12 '22 17:09 umakanth-fmr