remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.21k stars 1.72k forks source link

Nodemon hangs if started without internet connection #2096

Closed davidhusz closed 7 months ago

davidhusz commented 1 year ago

Expected behaviour

When I run npx nodemon server.js while connected to the internet, the server starts up as expected, preceded by nodemon printing its info messages. When I run the same without an internet connection, I expect it to behave the same.

Actual behaviour

When starting nodemon without an internet connection, the program hangs indefinitely, without printing anything to the terminal. This happens even when just running nodemon --help.

Steps to reproduce

  1. Disconnect your internet
  2. Invoke nodemon

nodemon --dump:

{
  run: false,
  required: false,
  timeout: 1000,
  options: {
    dump: true,
    ignore: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**',
      re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/
    ],
    watch: [ '*.*', re: /.*\..*/ ],
    monitor: [
      '*.*',
      '!**/.git/**',
      '!**/.nyc_output/**',
      '!**/.sass-cache/**',
      '!**/bower_components/**',
      '!**/coverage/**',
      '!**/node_modules/**'
    ],
    ignoreRoot: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**'
    ],
    restartable: 'rs',
    colours: true,
    execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' },
    stdin: true,
    runOnChangeOnly: false,
    verbose: false,
    signal: 'SIGUSR2',
    stdout: true,
    watchOptions: {},
    execOptions: {
      script: 'server.js',
      exec: 'node',
      args: [],
      scriptPosition: 0,
      nodeArgs: undefined,
      execArgs: [],
      ext: 'js,mjs,json',
      env: {}
    }
  },
  load: [Function (anonymous)],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [],
  watchInterval: null,
  signal: 'SIGUSR2',
  command: {
    raw: { executable: 'node', args: [ 'server.js' ] },
    string: 'node server.js'
  }
}
remy commented 1 year ago

Yoinks! Definitely need to fix that. I used to work offline all the time pre-pandemic times, so hars definitely not acceptable!

On Mon, 16 Jan 2023, 00:43 David Husz, @.***> wrote:

  • Versions: @., @.
  • nodemon -v: 2.0.20
  • Operating system/terminal environment (powershell, gitshell, etc): fish on gnome-terminal on ubuntu
  • Using Docker? What image: no
  • Command you ran: npx nodemon server.js

Expected behaviour

When I run npx nodemon server.js while connected to the internet, the server starts up as expected, preceded by nodemon printing its info messages. When I run the same without an internet connection, I expect it to behave the same. Actual behaviour

When starting nodemon without an internet connection, the program hangs indefinitely, without printing anything to the terminal. This happens even when just running nodemon --help. Steps to reproduce

  1. Disconnect your internet
  2. Invoke nodemon

nodemon --dump:

{ run: false, required: false, timeout: 1000, options: { dump: true, ignore: [ '/.git/', '/.nyc_output/', '/.sass-cache/', '/bower_components/', '/coverage/', '/node_modules/', re: /..\/.git\/..|..\/.nyc_output\/..|..\/.sass-cache\/..|..\/bower_components\/..|..\/coverage\/..|..\/node_modules\/../ ], watch: [ '.', re: /.../ ], monitor: [ '.', '!/.git/', '!/.nyc_output/', '!/.sass-cache/', '!/bower_components/', '!/coverage/', '!/node_modules/' ], ignoreRoot: [ '/.git/', '/.nyc_output/', '/.sass-cache/', '/bower_components/', '/coverage/', '/node_modules/' ], restartable: 'rs', colours: true, execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' }, stdin: true, runOnChangeOnly: false, verbose: false, signal: 'SIGUSR2', stdout: true, watchOptions: {}, execOptions: { script: 'server.js', exec: 'node', args: [], scriptPosition: 0, nodeArgs: undefined, execArgs: [], ext: 'js,mjs,json', env: {} } }, load: [Function (anonymous)], reset: [Function: reset], lastStarted: 0, loaded: [], watchInterval: null, signal: 'SIGUSR2', command: { raw: { executable: 'node', args: [ 'server.js' ] }, string: 'node server.js' } }

— Reply to this email directly, view it on GitHub https://github.com/remy/nodemon/issues/2096, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADLBBMTGSSZJKMYZ66ZG3WSSKSPANCNFSM6AAAAAAT4FH4MM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

github-actions[bot] commented 1 year ago

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up. Thank you for contributing <3

sam-b-slingshot commented 1 year ago

I'm bumping this ^^

nejclovrencic commented 1 year ago

I think this is an issue with npx and not nodemon itself. npx tries to check for the latest version before running the package, and the network call fails:

DEBUG=* npx nodemon index.js
  agentkeepalive sock[0#registry.npmjs.org:443::::::::true:::::::::::::] create, timeout 300001ms +0ms
  agentkeepalive sock[0#registry.npmjs.org:443::::::::true:::::::::::::](requests: 1, finished: 0) error: Error: getaddrinfo ENOTFOUND registry.npmjs.org
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'registry.npmjs.org'
}, listenerCount: 2 +5ms
remy commented 1 year ago

I think this is nodemon itself through the update check. It needs to have either a timeout or a safeguard (I know that try/catch doesn't particularly work).

nejclovrencic commented 1 year ago

It only happens to me if I don't have nodemon installed globally, thus I suspected npx. There are also other similar issues reported there, such as https://github.com/npm/cli/issues/6157. If I install nodemon globally and disconnect the internet, it seems to work fine.

remy commented 1 year ago

Woah, that's weird then!

On Tue, 14 Feb 2023, 10:06 Nejc Lovrencic, @.***> wrote:

It only happens to me if I don't have nodemon installed globally, thus I suspected npx. There are also other similar issues reported there, such as npm/cli#6157 https://github.com/npm/cli/issues/6157. If I install nodemon globally and disconnect the internet, it seems to work fine.

— Reply to this email directly, view it on GitHub https://github.com/remy/nodemon/issues/2096#issuecomment-1429459924, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAADLBAY37EWT25CEUWENQLWXNKK3ANCNFSM6AAAAAAT4FH4MM . You are receiving this because you were mentioned.Message ID: @.***>

davidhusz commented 1 year ago

I just tried out what @nejclovrencic mentioned and can confirm that the bug also only happens for me when nodemon is not installed globally. Interestingly, as long as it's installed globally it works both when invoking it via nodemon as well as via npx nodemon.

DKdev117 commented 11 months ago

can you assign this issue to me?

I will try to solve this issue.

remy commented 11 months ago

@DKdev117 doesn't need to be assigned, you can create a PR (ideally with tests)

DKdev117 commented 11 months ago

@remy Ok sir thank you

iamabhshk commented 7 months ago

Is this issue resolved?

remy commented 7 months ago

@iamabhshk no - have you seen it lately or are you just asking (because you want to fix it)?

iamabhshk commented 7 months ago

@remy I mean I just checked from my end but couldn't see such behavior which was mentioned by @davidhusz So just curious if its fixed, if not I would like to have a look at it

remy commented 7 months ago

Finally got around to giving this a proper test. It's actually just npx that is the issue.

You get the same behaviour if you disconnect from the web and run any other npx xxx command that can't be loaded from a parent directory (which is why npx nodemon works when you have nodemon installed globally).

Try the following (assuming you don't have enhance globally):

npx "@enhance/cli@latest" new ./myproject -y

It's hang in the same way.

I suggest @davidhusz raise this (in a non-nodemon specific way) with npm 👍