Title: Windows inet_pton(socket.AF_INET6, 'localhost') raises ValueError instead of socket.error
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 2.7
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: paul.moore, steve.dower, tim.golden, vitaly.krug, zach.ware
Priority: normal Keywords:

Created on 2018-04-02 17:18 by vitaly.krug, last changed 2018-04-02 22:28 by vitaly.krug. This issue is now closed.

Messages (5)
msg314814 - (view) Author: Vitaly Kruglikov (vitaly.krug) Date: 2018-04-02 17:18
I am seeing this with `socket.AF_INET6` on Windows running python 2.7.14
[00:02:33]   File "C:\projects\pika\pika\adapters\", line 153, in _check_already_resolved
[00:02:33]     socket.inet_pton(socket.AF_INET6, 'localhost')
[00:02:33]   File "C:\Python27\lib\site-packages\twisted\python\", line 68, in inet_pton
[00:02:33]     raise ValueError("Illegal characters: %r" % (''.join(x),))
[00:02:33] ValueError: Illegal characters: 't'

With `socket.AF_INET`, `socket.inet_pton(socket.AF_INET, 'localhost')` raises `socket.error` as expected.

For comparison, with Python 2.7.10 running on OS X, both AF_INET and AF_INET6 raise `socket.error`.
msg314815 - (view) Author: Vitaly Kruglikov (vitaly.krug) Date: 2018-04-02 17:27
This behavior goes against the socket documentation which states "Supported values for address_family are currently AF_INET and AF_INET6. If the IP address string ip_string is invalid, *socket.error* will be raised."
msg314820 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2018-04-02 18:11
Your traceback seems to include both pika and twisted, and as best I can tell, `socket.inet_pton` does not exist on Windows in Python 2.7.  If I've diagnosed this incorrectly, please reopen the ticket with a reproducer that does not depend on pika or twisted.
msg314822 - (view) Author: Vitaly Kruglikov (vitaly.krug) Date: 2018-04-02 18:57
Zachary, thank you for noticing that Twisted is involved. inet_pton definitely exists on Windows 2.7.14, but it turns out that Twisted monkey-patches it if `socket.inet_pton(socket.AF_INET6, "::")` fails.

Aha! - but this suggests that Window's Python 2.7.14 implementation of `socket.inet_pton()` has a bug in that it fails to recognize '::' as the the IPv6 unspecified address 0:0:0:0:0:0:0:0, so `socket.inet_pton(socket.AF_INET6, "::")` fails. I wonder if this exists on Windows Python3 implementations?
msg314833 - (view) Author: Vitaly Kruglikov (vitaly.krug) Date: 2018-04-02 22:28
Indeed, confirmed no `inet_pton()` on Windows in Python 2.7 :(.
Date User Action Args
2018-04-02 22:28:14vitaly.krugsetmessages: + msg314833
2018-04-02 18:57:42vitaly.krugsetmessages: + msg314822
2018-04-02 18:11:36zach.waresetstatus: open -> closed
resolution: third party
messages: + msg314820

stage: resolved
2018-04-02 17:27:12vitaly.krugsetmessages: + msg314815
2018-04-02 17:18:22vitaly.krugsettype: behavior
2018-04-02 17:18:03vitaly.krugcreate