Skip to content

Commit 74c7323

Browse files
author
Michael Smith
committed
deps: @npmcli/[email protected]
1 parent edc4ab3 commit 74c7323

4 files changed

Lines changed: 68 additions & 8 deletions

File tree

‎node_modules/@npmcli/agent/lib/agents.js‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,56 @@ module.exports = class Agent extends AgentBase {
203203

204204
return super.addRequest(request, options)
205205
}
206+
207+
// When connect() rejects, agent-base removes only its placeholder socket, so Node never drains this.requests[name] and requests queued past maxSockets hang forever.
208+
// On a failure we dispatch the next queued request ourselves.
209+
// See npm/cli#9386 and TooTallNate/proxy-agents#427.
210+
createSocket (req, options, cb) {
211+
super.createSocket(req, options, (err, socket) => {
212+
if (err) {
213+
this.#drainPendingRequests(req, options)
214+
}
215+
cb(err, socket)
216+
})
217+
}
218+
219+
// Dispatch the next request queued behind maxSockets, reusing the slot the failed connection freed.
220+
#drainPendingRequests (failedReq, options) {
221+
const name = this.getName(options)
222+
const queue = this.requests[name]
223+
if (!queue || queue.length === 0) {
224+
return
225+
}
226+
227+
// Node's removeSocket() picks a queued request without shifting it off, so drop the failed one to avoid dispatching it twice.
228+
const failedIndex = queue.indexOf(failedReq)
229+
if (failedIndex !== -1) {
230+
queue.splice(failedIndex, 1)
231+
}
232+
if (queue.length === 0) {
233+
delete this.requests[name]
234+
return
235+
}
236+
237+
// Safety belt: only dispatch if a socket slot is genuinely free.
238+
const socketCount = this.sockets[name] ? this.sockets[name].length : 0
239+
if (socketCount >= this.maxSockets || this.totalSocketCount >= this.maxTotalSockets) {
240+
return
241+
}
242+
243+
const nextReq = queue.shift()
244+
if (queue.length === 0) {
245+
delete this.requests[name]
246+
}
247+
248+
// All queued requests share this origin, so the failed request's options suit the next one.
249+
// createSocket() recurses here if this connection also fails, draining the whole queue.
250+
this.createSocket(nextReq, options, (err, socket) => {
251+
if (err) {
252+
nextReq.onSocket(null, err)
253+
} else {
254+
nextReq.onSocket(socket)
255+
}
256+
})
257+
}
206258
}

‎node_modules/@npmcli/agent/lib/options.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const normalizeOptions = (opts) => {
3737
// remove timeout since we already used it to set our own idle timeout
3838
delete normalized.timeout
3939

40+
// since opts is often passed when initiating requests, it may contain
41+
// headers, which should not be saved in an agent
42+
delete normalized.headers
43+
4044
return normalized
4145
}
4246

‎node_modules/@npmcli/agent/package.json‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/agent",
3-
"version": "4.0.0",
3+
"version": "4.0.2",
44
"description": "the http/https agent used by the npm cli",
55
"main": "lib/index.js",
66
"scripts": {
@@ -29,8 +29,10 @@
2929
},
3030
"templateOSS": {
3131
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
32-
"version": "4.25.0",
33-
"publish": "true"
32+
"version": "4.30.0",
33+
"publish": "true",
34+
"updateNpm": false,
35+
"latestCiVersion": 24
3436
},
3537
"dependencies": {
3638
"agent-base": "^7.1.0",
@@ -40,11 +42,11 @@
4042
"socks-proxy-agent": "^8.0.3"
4143
},
4244
"devDependencies": {
43-
"@npmcli/eslint-config": "^5.0.0",
44-
"@npmcli/template-oss": "4.25.0",
45-
"minipass-fetch": "^4.0.1",
45+
"@npmcli/eslint-config": "^6.0.0",
46+
"@npmcli/template-oss": "4.30.0",
47+
"ip-address": "^10.1.0",
48+
"minipass-fetch": "^5.0.0",
4649
"nock": "^14.0.3",
47-
"socksv5": "^0.0.6",
4850
"tap": "^16.3.0"
4951
},
5052
"repository": {

‎package-lock.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,9 @@
16551655
}
16561656
},
16571657
"node_modules/@npmcli/agent": {
1658-
"version": "4.0.0",
1658+
"version": "4.0.2",
1659+
"resolved": "https://registry.npmjs.org/@npmcli/agent/-/agent-4.0.2.tgz",
1660+
"integrity": "sha512-EUEuWAxnL07Sp5/iC/1X6Xj+XThUvnbei9zfRWZdEXa7lss9RTHMhAHBeg+MZ5To9s/gGaSI+UwZTPdYMvKSeg==",
16591661
"inBundle": true,
16601662
"license": "ISC",
16611663
"dependencies": {

0 commit comments

Comments
 (0)