Invalid host/port specified error on Windows #139

Closed
fschulze opened this Issue Oct 12, 2016 · 13 comments

Projects

None yet

3 participants

@fschulze

We use waitress in devpi like this:

  serve(app, host=host, port=port, threads=50)

and on Windows got #138 with waitress 1.0. To work around that I tried to change to the following:

  serve(app, listen="%s:%s" % (host, port), threads=50)

But then I got ValueError: Invalid host/port specified.

This only happens on Windows, Linux and OS X is fine. For now we pinned to waitress<1.

@mmerickel
Member

For what values of host/port is this an issue? Everything? Interface names? Interface addresses? IPv6?

@fschulze

In the tests and manually with localhost:3141.

@mmerickel
Member

The waitress test suite is failing for you on windows? We have CI setup so it would be good to know what the difference is there.

https://ci.appveyor.com/project/mmerickel/waitress

@mmerickel
Member

I see now that our CI is only running python 3 and the bug appears to be only on python 2.

@bertjwregeer
Member

I'm going to need to spin up a Windows VM to test this. I have no idea why getaddrinfo would be failing...

@fschulze

If you point me to a rough direction where to look in the code, I can debug it tomorrow.

@bertjwregeer
Member
bertjwregeer commented Oct 13, 2016 edited

@fschulze https://github.com/Pylons/waitress/blob/master/waitress/adjustments.py#L245

This is the try block that it is failing on. Most likely getaddrinfo is failing for some reason. I'd have to know the reason.

It may be because localhost is not valid, there may need to be a change to remove localhost and set it to ''.

That is what 0.9.0 used to do: https://github.com/Pylons/waitress/blob/v0.9.0/waitress/adjustments.py#L182

However IMHO this is wrong, because '' means bind to all interfaces, not just localhost.

@bertjwregeer
Member

Or change localhost to 127.0.0.1 possibly? localhost could also mean ::1 though...

@fschulze

In FreeBSD jails it's not 127.0.0.1 either, so localhost should be looked up if possible. I'll try to debug it. Thanks for the pointers.

@fschulze

The problem is, that at https://github.com/Pylons/waitress/blob/master/waitress/adjustments.py#L252 port is a unicode string and getaddrinfo expects an integer. The try/except block swallows that exception and raises it's own ValueError. If I just hack it with int(port), then it proceeds, but I get #138 again. I haven't investigated if port is also unicode on Linux or OS X at that point and getaddrinfo handles it properly on those platforms.

@bertjwregeer
Member

On OS X/Linux/other UNIXY OS's port may also be a name from /etc/services

For example:

localhost:blackjack

Will start a socket on port 1025 as well...

This is why the port on those OS's is allowed to be a unicode/string.

@bertjwregeer
Member

Alright, #141 should fix this issue appropriately since it only affects Python 2 on Windows. Apparently I had a test for the 127.0.0.1:http case, and those were passing without issue on Windows on Python 3.5

@bertjwregeer
Member

Closed by #140 being merged.

@clrpackages clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue Oct 25, 2016
@fenrus75 fenrus75 + clrbuilder waitress: Autospec creation for update from version 1.0.0 to version …
…1.0.1

1.0.1 (2016-10-22)
------------------

Bugfixes
~~~~~~~~

- IPv6 support on Windows was broken due to missing constants in the socket
  module. This has been resolved by setting the constants on Windows if they
  are missing. See Pylons/waitress#138

- A ValueError was raised on Windows when passing a string for the port, on
  Windows in Python 2 using service names instead of port numbers doesn't work
  with `getaddrinfo`. This has been resolved by attempting to convert the port
  number to an integer, if that fails a ValueError will be raised. See
  Pylons/waitress#139
66307a4
@clrpackages clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue Jan 11, 2017
@fenrus75 fenrus75 + clrbuilder waitress: Autospec creation for update from version 1.0.0 to version …
…1.0.1

1.0.1 (2016-10-22)
------------------

Bugfixes
~~~~~~~~

- IPv6 support on Windows was broken due to missing constants in the socket
  module. This has been resolved by setting the constants on Windows if they
  are missing. See Pylons/waitress#138

- A ValueError was raised on Windows when passing a string for the port, on
  Windows in Python 2 using service names instead of port numbers doesn't work
  with `getaddrinfo`. This has been resolved by attempting to convert the port
  number to an integer, if that fails a ValueError will be raised. See
  Pylons/waitress#139
a111daa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment