Closed lukekarrys closed 2 months ago
Latest commit: 4650f933d24aef7f32246a4b0c03f36f7fa4b54d
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Updated (UTC) |
---|---|---|---|
proxy-agents | ✅ Ready (Inspect) | Visit Preview | Mar 29, 2024 11:48pm |
I updated the reproduction in #299 to include more examples and when I install agent-base
from this PR, it works as expected.
❯ npm i https://proxy-agents-git-fork-lukekarrys-lk-socket-pooling-tootallnate.vercel.app/agent-base.tgz
❯ node index.js
core
10 max sockets
727 total versions
1873533 total bytes
----------------------------------------
agent-base-sync
10 max sockets
727 total versions
1873533 total bytes
----------------------------------------
agent-base-async
10 max sockets
727 total versions
1873533 total bytes
----------------------------------------
https-proxy-agent
10 max sockets
727 total versions
1873533 total bytes
----------------------------------------
Fixes #299
This is a bit of a hack, but I went with this approach because it allows for all of the native socket pooling behavior in
http.Agent
to be used andconnect()
to keep it's async signature.The tradeoff is manipulating the internal
sockets
dictionary which isreadonly
(according to@types/node
) and therefore needs a lot of@ts-expect-error
comments. An alternative approach would require overwriting theaddRequest()
method with custom pooling code.The approach in this PR works by synchronously adding a fake socket to the pool so
this.sockets[originName].length
is accurate before any other requests are added. Then the socket is removed directly afterconnect()
finishes.