fix: hanging requests

PR #2998
This commit is contained in:
Zoltan Kochan
2020-11-26 00:35:20 +02:00
committed by GitHub
parent 4617faed96
commit dc5a0a102e
4 changed files with 17 additions and 3 deletions

View File

@@ -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.

View File

@@ -0,0 +1,5 @@
---
"@pnpm/npm-registry-agent": patch
---
Increase the default maximum number of connections to use per origin to 50 (from 15).

View File

@@ -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,

View File

@@ -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 {