jeffbski / wait-on

wait-on is a cross-platform command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available
MIT License
1.87k stars 77 forks source link

seems to not work #127

Open xenoterracide opened 2 years ago

xenoterracide commented 2 years ago

sorry, am I missing something? wrote this in typescript, it exits immediately. I know the server isn't responding yet, no error but the info logs are output.

import waitOn = require('wait-on')

console.info('start', new Date().toLocaleTimeString())
waitOn(
  {
    resources: ['http://localhost:3000'],
    delay: 10000,
    validateStatus: function (status) {
      console.error(status)
      return status >= 200 && status < 300 // default if not provided
    },
  },
  err => {
    console.error(err)
  },
)
console.info('end', new Date().toLocaleTimeString())
mhay10 commented 2 years ago

Having the same problem here

MahbodHastam commented 2 years ago

Same here

metcoder95 commented 2 years ago

Which Node version are you using? If greater than 17, Is you server listening to IPv6 or IPv4?

xenoterracide commented 2 years ago

16

kwiniarski97 commented 2 years ago

Your code is simply invalid. You are not having any "success" callback that would be called when the http://localhost:3000 finally responds. What happens right now, waitOn is waiting indefinitely for the resources to be active. Because waitOn is asynchronous, it will be scheduled while the rest of the code would execute. If you add timeout to the options, you would see error callback being called. e.g.

const waitOn = require('wait-on');

console.info('start', new Date().toLocaleTimeString());
waitOn(
  {
    resources: ['http://localhost:3000'],
    delay: 10000,
    timeout: 1000,
    validateStatus: function (status) {
      console.error(status);
      return status >= 200 && status < 300; // default if not provided
    },
  },
  (err) => {
    console.error(err);
  }
);
console.info('end', new Date().toLocaleTimeString());

Would fail after one second, https://stackblitz.com/edit/node-u9mhgz?file=index.js

If you want to use it either provide success callbacks and timeout or better yet use it with promises.

EvenCheng commented 2 years ago

I have this issue with node v.19. As @metcoder95 hinted, the problem went away after downgrading to 16.18.0

nephix commented 2 years ago

Same for me after upgrading from node 16.x to 18.x

Seems to be related to this issue:

https://github.com/nodejs/node/issues/41625 and this PR https://github.com/nodejs/node/pull/44731

Might be a good idea for wait-on to listen to ::1 / 0:0:0:0:0:0:0:1 as well when it involes localhost

eiskalteschatten commented 2 years ago

I am also having an issue since updating to Node 18. If I change back to Node 16, it seems to work fine.

nilsmehlhorn commented 2 years ago

Might be duplicate of #109. Try replacing localhost with 127.0.0.1. Worked for me on Node v18.

eiskalteschatten commented 2 years ago

Might be duplicate of #109. Try replacing localhost with 127.0.0.1. Worked for me on Node v18.

That worked for me perfectly! Thank you!

Konglomneshued commented 1 year ago

Might be duplicate of #109. Try replacing localhost with 127.0.0.1. Worked for me on Node v18.

Thank you so much! That worked for me.