Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ping and doctor commands fix for checking if registry is online (#…
…7789) Ping: Don't use cache so ping does not report ping sucess incorrectly if it's offline or no internet Doctor: Don't use cache for pinging the registry. Fixes: #5870 Fixes: #3576 Fixes: #4112 <details> <summary>Testing of ping and doctor </summary> ```sh # -- current npm last ping resuts in cached request replying PONG ~/workarea/npm-cli $ npm ping --registry=http://localhost:4873 -ddd npm verbose cli /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/node /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/npm npm info using [email protected] npm info using [email protected] npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/lib/node_modules/npm/npmrc npm silly config load:file:/Users/milaninfy/workarea/npm-cli/.npmrc npm silly config load:file:/Users/milaninfy/.npmrc npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/etc/npmrc npm verbose title npm ping npm verbose argv "ping" "--registry" "http://localhost:4873" "--loglevel" "silly" npm verbose logfile logs-max:10 dir:/Users/milaninfy/.npm/_logs/2024-09-26T20_37_04_583Z- npm verbose logfile /Users/milaninfy/.npm/_logs/2024-09-26T20_37_04_583Z-debug-0.log npm notice PING http://localhost:4873/ npm silly logfile start cleaning logs, removing 1 files npm silly logfile done cleaning log files npm http fetch GET http://localhost:4873/-/ping?write=true attempt 1 failed with ECONNREFUSED npm http fetch GET http://localhost:4873/-/ping?write=true attempt 2 failed with ECONNREFUSED npm http fetch GET http://localhost:4873/-/ping?write=true attempt 3 failed with ECONNREFUSED npm http fetch GET 200 http://localhost:4873/-/ping?write=true 70045ms (cache stale) npm notice PONG 70046ms npm verbose cwd /Users/milaninfy/workarea/npm-cli npm verbose os Darwin 23.6.0 npm verbose node v22.9.0 npm verbose npm v10.8.3 npm verbose exit 0 npm info ok # -- After the change npm last ping resuts in failure after retries ~/workarea/npm-cli $ lnpm ping --registry=http://localhost:4873 -ddd npm verbose cli /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/node /Users/milaninfy/workarea/npm-cli/index.js npm info using [email protected] npm info using [email protected] npm silly config load:file:/Users/milaninfy/workarea/npm-cli/npmrc npm silly config load:file:/Users/milaninfy/workarea/npm-cli/.npmrc npm silly config load:file:/Users/milaninfy/.npmrc npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/etc/npmrc npm verbose title npm ping npm verbose argv "ping" "--registry" "http://localhost:4873" "--loglevel" "silly" npm verbose logfile logs-max:10 dir:/Users/milaninfy/.npm/_logs/2024-09-26T20_38_51_059Z- npm verbose logfile /Users/milaninfy/.npm/_logs/2024-09-26T20_38_51_059Z-debug-0.log npm notice PING http://localhost:4873/ npm silly logfile start cleaning logs, removing 1 files npm http fetch GET http://localhost:4873/-/ping?write=true attempt 1 failed with ECONNREFUSED npm silly logfile done cleaning log files npm http fetch GET http://localhost:4873/-/ping?write=true attempt 2 failed with ECONNREFUSED npm http fetch GET http://localhost:4873/-/ping?write=true attempt 3 failed with ECONNREFUSED npm verbose type system npm verbose stack FetchError: request to http://localhost:4873/-/ping?write=true failed, reason: npm verbose stack at ClientRequest.<anonymous> (/Users/milaninfy/workarea/npm-cli/node_modules/minipass-fetch/lib/index.js:130:14) npm verbose stack at ClientRequest.emit (node:events:519:28) npm verbose stack at emitErrorEvent (node:_http_client:103:11) npm verbose stack at _destroy (node:_http_client:886:9) npm verbose stack at onSocketNT (node:_http_client:906:5) npm verbose stack at process.processTicksAndRejections (node:internal/process/task_queues:91:21) npm error code ECONNREFUSED npm error errno ECONNREFUSED npm error FetchError: request to http://localhost:4873/-/ping?write=true failed, reason: npm error at ClientRequest.<anonymous> (/Users/milaninfy/workarea/npm-cli/node_modules/minipass-fetch/lib/index.js:130:14) npm error at ClientRequest.emit (node:events:519:28) npm error at emitErrorEvent (node:_http_client:103:11) npm error at _destroy (node:_http_client:886:9) npm error at onSocketNT (node:_http_client:906:5) npm error at process.processTicksAndRejections (node:internal/process/task_queues:91:21) { npm error code: 'ECONNREFUSED', npm error errno: 'ECONNREFUSED', npm error type: 'system' npm error } npm error npm error If you are behind a proxy, please make sure that the npm error 'proxy' config is set properly. See: 'npm help config' npm verbose cwd /Users/milaninfy/workarea/npm-cli npm verbose os Darwin 23.6.0 npm verbose node v22.9.0 npm verbose npm v10.8.3 npm verbose exit 1 npm verbose code 1 npm error A complete log of this run can be found in: /Users/milaninfy/.npm/_logs/2024-09-26T20_38_51_059Z-debug-0.log # -- npm doctor ping resuts in success due to cache hit ~/workarea/npm-cli $ npm doctor --registry=http://localhost:4873 -ddd npm verbose cli /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/node /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/npm npm info using [email protected] npm info using [email protected] npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/lib/node_modules/npm/npmrc npm silly config load:file:/Users/milaninfy/workarea/npm-cli/.npmrc npm silly config load:file:/Users/milaninfy/.npmrc npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/etc/npmrc npm verbose title npm doctor npm verbose argv "doctor" "--registry" "http://localhost:4873" "--loglevel" "silly" npm verbose logfile logs-max:10 dir:/Users/milaninfy/.npm/_logs/2024-09-26T20_40_30_672Z- npm verbose logfile /Users/milaninfy/.npm/_logs/2024-09-26T20_40_30_672Z-debug-0.log npm info doctor Running checkup Connecting to the registry npm info doctor Pinging registry npm silly logfile start cleaning logs, removing 1 files npm silly logfile done cleaning log files npm http fetch GET http://localhost:4873/-/ping?write=true attempt 1 failed with ECONNREFUSED npm http fetch GET 200 http://localhost:4873/-/ping?write=true 48ms (cache stale) Ok # -- after the changes npm doctor ping correctly resuts in failure after retires ~/workarea/npm-cli $ lnpm doctor --registry=http://localhost:4873 -ddd npm verbose cli /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/node /Users/milaninfy/workarea/npm-cli/index.js npm info using [email protected] npm info using [email protected] npm silly config load:file:/Users/milaninfy/workarea/npm-cli/npmrc npm silly config load:file:/Users/milaninfy/workarea/npm-cli/.npmrc npm silly config load:file:/Users/milaninfy/.npmrc npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/etc/npmrc npm verbose title npm doctor npm verbose argv "doctor" "--registry" "http://localhost:4873" "--loglevel" "silly" npm verbose logfile logs-max:10 dir:/Users/milaninfy/.npm/_logs/2024-09-26T20_41_05_904Z- npm verbose logfile /Users/milaninfy/.npm/_logs/2024-09-26T20_41_05_904Z-debug-0.log npm info doctor Running checkup Connecting to the registry npm info doctor Pinging registry npm silly logfile start cleaning logs, removing 1 files npm http fetch GET http://localhost:4873/-/ping?write=true attempt 1 failed with ECONNREFUSED npm silly logfile done cleaning log files npm http fetch GET http://localhost:4873/-/ping?write=true attempt 2 failed with ECONNREFUSED npm http fetch GET http://localhost:4873/-/ping?write=true attempt 3 failed with ECONNREFUSED Not ok request to http://localhost:4873/-/ping?write=true failed, reason: ``` </detail>
- Loading branch information