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

Invalid host/port specified error on Windows #139

Closed
fschulze opened this issue Oct 12, 2016 · 15 comments
Closed

Invalid host/port specified error on Windows #139

fschulze opened this issue Oct 12, 2016 · 15 comments

Comments

@fschulze
Copy link

@fschulze fschulze commented Oct 12, 2016

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

@mmerickel mmerickel commented Oct 12, 2016

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

@fschulze
Copy link
Author

@fschulze fschulze commented Oct 12, 2016

In the tests and manually with localhost:3141.

@mmerickel
Copy link
Member

@mmerickel mmerickel commented Oct 12, 2016

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

@mmerickel mmerickel commented Oct 12, 2016

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

@bertjwregeer
Copy link
Member

@bertjwregeer bertjwregeer commented Oct 13, 2016

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

@fschulze
Copy link
Author

@fschulze fschulze commented Oct 13, 2016

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

@bertjwregeer
Copy link
Member

@bertjwregeer bertjwregeer commented Oct 13, 2016

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

@bertjwregeer bertjwregeer commented Oct 13, 2016

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

@fschulze
Copy link
Author

@fschulze fschulze commented Oct 13, 2016

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

@fschulze fschulze commented Oct 14, 2016

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

@bertjwregeer bertjwregeer commented Oct 14, 2016

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

@bertjwregeer bertjwregeer commented Oct 14, 2016

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

@bertjwregeer bertjwregeer commented Oct 22, 2016

Closed by #140 being merged.

clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue Oct 25, 2016
…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
clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue Jan 11, 2017
…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
clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue Jan 17, 2017
…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
clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue Feb 16, 2017
…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
clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue Mar 9, 2017
…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
clrpackages pushed a commit to clearlinux-pkgs/waitress that referenced this issue May 5, 2017
…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
@zart
Copy link

@zart zart commented Aug 16, 2017

FWIW, socket.getaddrinfo works with service names on windows python 2.x as well, it just doesn't like unicode:

Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getaddrinfo('localhost', 'ftp')
[(23, 1, 0, '', ('::1', 21, 0, 0)), (2, 1, 0, '', ('127.0.0.1', 21))]
>>> socket.getaddrinfo('localhost', u'ftp')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.error: getaddrinfo() argument 2 must be integer or string
@bertjwregeer
Copy link
Member

@bertjwregeer bertjwregeer commented Aug 16, 2017

That's good to know!

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.