Skip to content

[BUG] npm ping uses cache when registry is offline #5870

@Metritutus

Description

@Metritutus

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When using npm ping to check if a private registry was online, I noticed that it would claim a successful response after approximately 70000ms when the registry was definitely offline. I'm not sure if it's currently possible to configure the timeout period, but it would be very useful to be able to do so.

The private registry was a Verdaccio registry hosted on the local machine (launched with verdaccio --listen 127.0.0.1:4873), although I'm not sure this is of relevance for this issue.

Suspecting that there might be some sort of caching involved, I ran npm cache ls, which confirmed there was an entry in there for the ping request.

Interestingly, after cleaning the entry out of the cache, the next npm ping call still succeeds. It is only the subsequent ones (after the first ping since removing the entry from the cache) which fail as they should.

The commands and their output demonstrating the problem:

1) npm ping where the private registry is online:

npm ping --registry=http://127.0.0.1:4873/ --verbose

npm verb cli C:\Program Files\nodejs\node.exe C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm verb title npm ping
npm verb argv "ping" "--registry" "http://127.0.0.1:4873/" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_05_12_706Z-
npm verb logfile C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_05_12_706Z-debug-0.log
npm notice PING http://127.0.0.1:4873/
npm http fetch GET 200 http://127.0.0.1:4873/-/ping?write=true 33ms (cache miss)
npm notice PONG 35ms
npm verb exit 0
npm info ok

2) npm ping where the private registry is offline:

npm ping --registry=http://127.0.0.1:4873/ --verbose

npm verb cli C:\Program Files\nodejs\node.exe C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm verb title npm ping
npm verb argv "ping" "--registry" "http://127.0.0.1:4873/" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_05_56_431Z-
npm verb logfile C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_05_56_431Z-debug-0.log
npm notice PING http://127.0.0.1:4873/
npm http fetch GET 200 http://127.0.0.1:4873/-/ping?write=true 70061ms (cache stale)
npm notice PONG 70062ms
npm verb exit 0
npm info ok

3) npm cache clean the ping entry:

npm cache clean make-fetch-happen:request-cache:http://127.0.0.1:4873/-/ping?write=true --verbose

npm verb cli C:\Program Files\nodejs\node.exe C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm verb title npm cache clean make-fetch-happen:request-cache:http://127.0.0.1:4873/-/ping?write=true
npm verb argv "cache" "clean" "make-fetch-happen:request-cache:http://127.0.0.1:4873/-/ping?write=true" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_08_04_190Z-
npm verb logfile C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_08_04_190Z-debug-0.log
Deleted: make-fetch-happen:request-cache:http://127.0.0.1:4873/-/ping?write=true
npm verb exit 0
npm info ok

4) npm ping where the private registry is offline:

npm ping --registry=http://127.0.0.1:4873/ --verbose

npm verb cli C:\Program Files\nodejs\node.exe C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm verb title npm ping
npm verb argv "ping" "--registry" "http://127.0.0.1:4873/" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_09_01_885Z-
npm verb logfile C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_09_01_885Z-debug-0.log
npm notice PING http://127.0.0.1:4873/
npm notice PONG 70076ms
npm verb exit 0
npm info ok

5) npm ping where the private registry is offline:

npm ping --registry=http://127.0.0.1:4873/ --verbose

npm ping --registry=http://127.0.0.1:4873/ --verbose
npm verb cli C:\Program Files\nodejs\node.exe C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
npm info using [email protected]
npm info using [email protected]
npm verb title npm ping
npm verb argv "ping" "--registry" "http://127.0.0.1:4873/" "--loglevel" "verbose"
npm verb logfile logs-max:10 dir:C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_10_51_182Z-
npm verb logfile C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_10_51_182Z-debug-0.log
npm notice PING http://127.0.0.1:4873/
npm verb type system
npm verb stack FetchError: request to http://127.0.0.1:4873/-/ping?write=true failed, reason: connect ECONNREFUSED 127.0.0.1:4873
npm verb stack     at ClientRequest.<anonymous> (C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm verb stack     at ClientRequest.emit (node:events:513:28)
npm verb stack     at Socket.socketErrorListener (node:_http_client:494:9)
npm verb stack     at Socket.emit (node:events:525:35)
npm verb stack     at emitErrorNT (node:internal/streams/destroy:151:8)
npm verb stack     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm verb stack     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
npm verb cwd C:\Users\<REDACTED>
npm verb Windows_NT 10.0.22621
npm verb node v18.12.1
npm verb npm  v9.1.2
npm ERR! code ECONNREFUSED
npm ERR! syscall connect
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to http://127.0.0.1:4873/-/ping?write=true failed, reason: connect ECONNREFUSED 127.0.0.1:4873
npm ERR!     at ClientRequest.<anonymous> (C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at Socket.socketErrorListener (node:_http_client:494:9)
npm ERR!     at Socket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
npm ERR!  FetchError: request to http://127.0.0.1:4873/-/ping?write=true failed, reason: connect ECONNREFUSED 127.0.0.1:4873
npm ERR!     at ClientRequest.<anonymous> (C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at Socket.socketErrorListener (node:_http_client:494:9)
npm ERR!     at Socket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   syscall: 'connect',
npm ERR!   address: '127.0.0.1',
npm ERR!   port: 4873,
npm ERR!   type: 'system'
npm ERR! }
npm ERR!
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly.  See: 'npm help config'
npm verb exit 1
npm verb code 1

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<REDACTED>\AppData\Local\npm-cache\_logs\2022-11-18T16_10_51_182Z-debug-0.log

Expected Behavior

npm ping responses should not be cached. It should accurately report whether or not the specified registry is actually online, rather than returning a cached response after timing out.

Steps To Reproduce

  1. With the private registry online, run the following command: npm ping --registry=http://127.0.0.1:4873/ --verbose
  2. Shut down the private registry.
  3. With the private registry offline, run the following command: npm ping --registry=http://127.0.0.1:4873/ --verbose

Environment

  • npm: 9.1.2
  • Node.js: 18.12.1
  • OS Name: Windows 11 22H2 (OS Build 22621.674)
  • System Model Name: N/A
  • npm config:
; "builtin" config from C:\Users\<REDACTED>\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\<REDACTED>\\AppData\\Roaming\\npm"

; "cli" config from command line options

location = "project"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v18.12.1
; npm local prefix = C:\Users\<REDACTED>
; npm version = 9.1.2
; cwd = C:\Users\<REDACTED>
; HOME = C:\Users\<REDACTED>
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issueRelease 9.xwork is associated with a specific npm 9 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions