Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa5f233

Browse files
fix: don't use the request signal in the agent (#324)
Following an upgrade from `13.0.1` to `14.0.1` (which included upgrading `@npmcli/agent` from `2.0.0` to `3.0.0`), we've seen strange behaviour: a request works the first time, then immediately times out after that. We're setting a `signal` on each request, which due to changes in `@npmcli/agent` is then also used by the agent for connections. The problem is that the original signal is used for all requests due to agent caching. Once it's been used (i.e. after the first time a request is made), no connections are possible (as they're immediately rejected). This change resolves our issue by removing the signal from the agent. I looked into adding a test, but I don't think it's possible without making real network requests. --------- Co-authored-by: Gar <[email protected]>
1 parent 2248215 commit fa5f233

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/remote.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const RETRY_TYPES = [
3535
// following redirects (through the cache if necessary)
3636
// and verifying response integrity
3737
const remoteFetch = (request, options) => {
38-
const agent = getAgent(request.url, options)
38+
// options.signal is intended for the fetch itself, not the agent. Attaching it to the agent will re-use that signal across multiple requests, which prevents any connections beyond the first one.
39+
const agent = getAgent(request.url, { ...options, signal: undefined })
3940
if (!request.headers.has('connection')) {
4041
request.headers.set('connection', agent ? 'keep-alive' : 'close')
4142
}

0 commit comments

Comments
 (0)