From dc5a0a102e4668816ca8d3784630abc7024bc947 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Thu, 26 Nov 2020 00:35:20 +0200 Subject: [PATCH] fix: hanging requests PR #2998 --- .changeset/light-geese-peel.md | 5 +++++ .changeset/twenty-cats-return.md | 5 +++++ packages/npm-registry-agent/src/index.ts | 8 +++++--- .../src/createNewStoreController.ts | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changeset/light-geese-peel.md create mode 100644 .changeset/twenty-cats-return.md diff --git a/.changeset/light-geese-peel.md b/.changeset/light-geese-peel.md new file mode 100644 index 0000000000..3609d57627 --- /dev/null +++ b/.changeset/light-geese-peel.md @@ -0,0 +1,5 @@ +--- +"@pnpm/store-connection-manager": patch +--- + +The maximum number of allowed connections increased to 3 times the number of network concurrency. This should fix the socket timeout issues that sometimes happen. diff --git a/.changeset/twenty-cats-return.md b/.changeset/twenty-cats-return.md new file mode 100644 index 0000000000..fcf36a1e72 --- /dev/null +++ b/.changeset/twenty-cats-return.md @@ -0,0 +1,5 @@ +--- +"@pnpm/npm-registry-agent": patch +--- + +Increase the default maximum number of connections to use per origin to 50 (from 15). diff --git a/packages/npm-registry-agent/src/index.ts b/packages/npm-registry-agent/src/index.ts index 7501772852..a08da02c52 100644 --- a/packages/npm-registry-agent/src/index.ts +++ b/packages/npm-registry-agent/src/index.ts @@ -7,6 +7,8 @@ import SocksProxyAgent = require('socks-proxy-agent') const HttpsAgent = HttpAgent.HttpsAgent +const DEFAULT_MAX_SOCKETS = 50 + const AGENT_CACHE = new LRU({ max: 50 }) export interface AgentOptions { @@ -64,13 +66,13 @@ export default function getAgent (uri: string, opts: AgentOptions) { cert: opts.cert, key: opts.key, localAddress: opts.localAddress, - maxSockets: opts.maxSockets ?? 15, + maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS, rejectUnauthorized: opts.strictSSL, timeout: agentTimeout, } as any) // eslint-disable-line @typescript-eslint/no-explicit-any : new HttpAgent({ localAddress: opts.localAddress, - maxSockets: opts.maxSockets ?? 15, + maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS, timeout: agentTimeout, } as any) // eslint-disable-line @typescript-eslint/no-explicit-any AGENT_CACHE.set(key, agent) @@ -152,7 +154,7 @@ function getProxy ( host: proxyUrl.hostname, key: opts.key, localAddress: opts.localAddress, - maxSockets: opts.maxSockets ?? 15, + maxSockets: opts.maxSockets ?? DEFAULT_MAX_SOCKETS, path: proxyUrl.pathname, port: proxyUrl.port, protocol: proxyUrl.protocol, diff --git a/packages/store-connection-manager/src/createNewStoreController.ts b/packages/store-connection-manager/src/createNewStoreController.ts index c6fe017882..92acc82a93 100644 --- a/packages/store-connection-manager/src/createNewStoreController.ts +++ b/packages/store-connection-manager/src/createNewStoreController.ts @@ -58,6 +58,8 @@ export default async ( storeDir: opts.storeDir, strictSSL: opts.strictSsl ?? true, userAgent: opts.userAgent, + maxSockets: opts.networkConcurrency != null + ? (opts.networkConcurrency * 3) : undefined, }) await fs.mkdir(opts.storeDir, { recursive: true }) return {