Skip to content

Commit cd214d4

Browse files
committed
Merge remote-tracking branch 'nodejs/main'
* nodejs/main: (23 commits) Bumped v7.5.0 (nodejs#4091) Removed clients with unrecoverable errors from the Pool (nodejs#4088) feat: Allow disabling autoSelectFamily in an Agent (nodejs#4070) chore: update cache tests (nodejs#4027) fix: Fix retry-handler.js when retry-after header is a Date (nodejs#4084) feat: add mock call history to access request configuration in test (nodejs#4029) feat(docs): button to switch dark and light mode (nodejs#4044) Bumped v7.4.0 (nodejs#4071) fix: fix EnvHttpProxyAgent for the Node.js bundle (nodejs#4064) chore: update WPT (nodejs#4062) chore: update WPT (nodejs#4028) fix: handle missing vary header values (nodejs#4031) fix: do not throw unhandled exception when data is undefined in interceptor.reply (nodejs#4036) test: fix windows wpt (nodejs#4050) feat: mark `EnvHttpProxyAgent` as stable (nodejs#4049) don't check AbortSignal maxListeners on some node versions (nodejs#4045) feat(docs): copy to clipboard button (nodejs#4037) docs: fix incorrect method signature of `onResponseError` (nodejs#4030) docs: document about global dispatcher and errors (nodejs#3987) (nodejs#4014) chore: update WPT (nodejs#4011) ...
2 parents 2028094 + a180465 commit cd214d4

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/dispatcher/client.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class Client extends DispatcherBase {
205205
allowH2,
206206
socketPath,
207207
timeout: connectTimeout,
208-
...(autoSelectFamily ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
208+
...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
209209
...connect
210210
})
211211
}
@@ -421,9 +421,6 @@ async function connect (client) {
421421
assert(socket)
422422

423423
try {
424-
if (socket.alpnProtocol === 'h2') {
425-
throw new InvalidArgumentError('ALPN negotiation failed')
426-
}
427424
client[kHTTPContext] = await connectH1(client, socket)
428425
} catch (err) {
429426
socket.destroy().on('error', noop)

lib/dispatcher/pool.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Pool extends PoolBase {
5858
allowH2,
5959
socketPath,
6060
timeout: connectTimeout,
61-
...(autoSelectFamily ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
61+
...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
6262
...connect
6363
})
6464
}
@@ -70,6 +70,20 @@ class Pool extends PoolBase {
7070
? { ...options.interceptors }
7171
: undefined
7272
this[kFactory] = factory
73+
74+
this.on('connectionError', (origin, targets, error) => {
75+
// If a connection error occurs, we remove the client from the pool,
76+
// and emit a connectionError event. They will not be re-used.
77+
// Fixes https://github.com/nodejs/undici/issues/3895
78+
for (const target of targets) {
79+
// Do not use kRemoveClient here, as it will close the client,
80+
// but the client cannot be closed in this state.
81+
const idx = this[kClients].indexOf(target)
82+
if (idx !== -1) {
83+
this[kClients].splice(idx, 1)
84+
}
85+
}
86+
})
7387
}
7488

7589
[kGetDispatcher] () {

0 commit comments

Comments
 (0)