delvedor / hpagent

A ready to use http and https agent for working with proxies that keeps connections alive!
MIT License
182 stars 36 forks source link

Issue with secure socket creation errors #113

Open gguimond opened 1 year ago

gguimond commented 1 year ago

When using an HTTPS agent, the creation of the secure socket can throw and as a result it raises an exception caught at node process level and the request is hanging forever (or timeout).

https://github.com/delvedor/hpagent/blob/96f45f1d40bfbdfd0fcc84cdba056be6e0fb8f4c/index.js#L102

To reproduce, specify a wrong key/certificate pair to agent options for example :

await request({
      method: 'GET',
      hostname: SERVER_HOSTNAME,
      port: server.address().port,
      path: '/',
      agent: new HttpsProxyAgent({
        keepAlive: true,
        keepAliveMsecs: 1000,
        maxSockets: 256,
        maxFreeSockets: 256,
        scheduling: 'lifo',
        /**
         * Enable SSL 2 ways and generate a 'createConnection' error with wrong key/cert pair
         */
        key: 'wrongkey',
        cert: 'wrongca',
        proxy: `https://${PROXY_HOSTNAME}:${proxy.address().port}`
      })
    })

The PR is on its way if you wish.