Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seems to not work #127

Open
xenoterracide opened this issue Aug 9, 2022 · 11 comments
Open

seems to not work #127

xenoterracide opened this issue Aug 9, 2022 · 11 comments

Comments

@xenoterracide
Copy link

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
Copy link

mhay10 commented Aug 10, 2022

Having the same problem here

@MahbodHastam
Copy link

Same here

@metcoder95
Copy link

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

@xenoterracide
Copy link
Author

16

@kwiniarski97
Copy link

kwiniarski97 commented Sep 14, 2022

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
Copy link

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

@nephix
Copy link

nephix commented Nov 2, 2022

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

Seems to be related to this issue:

nodejs/node#41625 and this PR nodejs/node#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
Copy link

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

@nilsmehlhorn
Copy link

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

@eiskalteschatten
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants