Issue 25138: test_socket: socket.EAI_NODATA doesn't exist on FreeBSD (original) (raw)

Created on 2015-09-16 06:52 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg250817 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-16 06:52
test_socket.test_idna() uses socket.EAI_NODATA constant which doesn't exists on FreeBSD. http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.0%203.x/builds/3697/steps/test/logs/stdio ====================================================================== ERROR: test_idna (test.test_socket.GeneralModuleTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/home/buildbot/python/3.x.koobs-freebsd10/build/Lib/test/test_socket.py", line 1294, in test_idna socket.gethostbyname('python.org') socket.gaierror: [Errno 8] hostname nor servname provided, or not known During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/home/buildbot/python/3.x.koobs-freebsd10/build/Lib/test/test_socket.py", line 1296, in test_idna if e.errno == socket.EAI_NODATA: AttributeError: module 'socket' has no attribute 'EAI_NODATA'
msg251059 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-09-19 07:01
Maybe it is good enough use something like this as a workaround, with an appropriate comment: if e.errno == getattr(socket, "EAI_NODATA", None): # Symbol not defined on FreeBSD However I wonder if it would be reasonable to set this constant (and similar undefined error codes) to a dummy value like None by default in the module. The documentation already says “for a few symbols, default values are provided”.
msg251060 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-09-19 07:03
Actually, None is probably a bad default, since gaierror().errno also defaults to None. Maybe choose some other unlikely non-integer object instead.
msg251063 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-19 08:02
It would be better to catch the FreeBSD error code when the hostname is not known.
msg251203 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-09-21 05:48
Looking at this more closely, the check seems to be there just to check if basic DNS lookups are working. It was added for Issue 12804. One option might be to replace it with a support.transient_internet() handler: # Check for internet access before running test (issue #12804). with support.transient_internet('python.org'): socket.gethostbyname('python.org') # these should all be successful ... According to the socket module source code, gethostbyname() calls the OS-level getaddrinfo() rather gethostbyname(), hence the “gaierror” handling. The error codes that get raised seem to be a platform-dependent mess, but transient_internet() looks like it catches EAI_NONAME, _FAIL, _NODATA and WSANO_DATA (among others). EAI_NODATA seems to have been removed from RFC 3493 and current Posix, but was apparently originally meant to be for looking up records that did exist but (say) did not have any IP v4 addresses.
msg251209 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-21 07:09
New changeset f13a5b5a2824 by Victor Stinner in branch '3.4': Issue #25138: test_socket.test_idna() uses support.transient_internet() instead https://hg.python.org/cpython/rev/f13a5b5a2824 New changeset a7baccf0b1c2 by Victor Stinner in branch '3.5': Merge 3.4 (test_socket, issue #25138) https://hg.python.org/cpython/rev/a7baccf0b1c2 New changeset d8dd06ab00e4 by Victor Stinner in branch 'default': Merge 3.5 (test_socket, issue #25138) https://hg.python.org/cpython/rev/d8dd06ab00e4
msg251210 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-21 07:12
> Looking at this more closely, the check seems to be there just to check if basic DNS lookups are working. It was added for Issue 12804. One option might be to replace it with a support.transient_internet() handler: (...) Oh good idea. This context manager sets also a timeout to 30 seconds which can help to skip the test only platforms with flacky internet connections. By the way, I also saw the test failing randomly on the Windows 8.1 buildbot. I hope that support.transient_internet() will also skip the tes on this case. I close the issue since the initial issue is fixed. Thanks Martin for the hint ;)
History
Date User Action Args
2022-04-11 14:58:21 admin set github: 69325
2015-09-21 07:12:31 vstinner set status: open -> closedresolution: fixedmessages: +
2015-09-21 07:09:04 python-dev set nosy: + python-devmessages: +
2015-09-21 05:48:38 martin.panter set nosy: + nadeem.vawdamessages: +
2015-09-19 08:02:19 vstinner set messages: +
2015-09-19 07:03:37 martin.panter set messages: +
2015-09-19 07:01:20 martin.panter set nosy: + martin.pantermessages: +
2015-09-16 06:52:45 vstinner create