This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: test_getsockaddrarg occasional failure
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, koobs, neirbowj, neologix, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2013-12-03 10:17 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
find_unused_race.diff neologix, 2014-07-24 18:46 review
Messages (11)
msg205099 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-12-03 10:17
It's on the FreeBSD 10.0 buildbot:
http://buildbot.python.org/all/builders/AMD64%20FreeBSD%2010.0%203.x/builds/1169

======================================================================
ERROR: test_getsockaddrarg (test.test_socket.GeneralModuleTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/buildbot/koobs-freebsd10/3.x.koobs-freebsd10/build/Lib/test/test_socket.py", line 1159, in test_getsockaddrarg
    sock.bind((host, port))
OSError: [Errno 48] Address already in use
msg205131 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-12-03 18:09
This test is inherently subject to a race condition:
"""
        port = support.find_unused_port()
        [...]
        try:
            self.assertRaises(OverflowError, sock.bind, (host, big_port))
            self.assertRaises(OverflowError, sock.bind, (host, neg_port))
            sock.bind((host, port))
        finally:
            sock.close()
"""

The buildbot being set up ton run the test suite with "-j4" is
probably the most important factor.

A possibility would be to try the find_unused_port() + bind() in a
loop a couple times.
msg205227 - (view) Author: John W. O'Brien (neirbowj) Date: 2013-12-04 15:25
For reference:

CPython code comments showing that this may be an anticipated problem:

http://hg.python.org/cpython/file/0830670a9d9d/Lib/test/support/__init__.py#l562

An example of another project that seems to have tackled this problem in the way neologix suggests:

http://openvswitch.org/pipermail/dev/2013-April/026430.html

I am inclined to frame this issue as a choice between LBYL (try to predict, subject to the race, whether a port will be available) and EAFP (blindly try a few random high ports before inferring failure).
msg223818 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-24 08:28
Clearly the long term solution is to fix the problems in the cpython code referenced in msg205227, but in the short term is it worth attempting a work around as suggested in msg205131 ?
msg223868 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2014-07-24 18:46
Here's a patch.
msg223980 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-25 17:45
New changeset 897c9e6ddb1a by Charles-François Natali in branch '3.4':
Issue #19875: Fix random test_getsockaddrarg() failure.
http://hg.python.org/cpython/rev/897c9e6ddb1a

New changeset 619feea86ce4 by Charles-François Natali in branch 'default':
Issue #19875: Fix random test_getsockaddrarg() failure.
http://hg.python.org/cpython/rev/619feea86ce4
msg223981 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2014-07-25 17:54
Should be fixed now, thanks!
msg224048 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2014-07-26 12:27
Thank you for taking care of this Charles-François :) Requesting backport to 3.3 and 2.7 too please, both are open for fixes.
msg224051 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-26 12:45
New changeset 57e3c4ae37ea by Charles-François Natali in branch '2.7':
Issue #19875: Fix random test_getsockaddrarg() failure.
http://hg.python.org/cpython/rev/57e3c4ae37ea
msg224052 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2014-07-26 12:46
Backported to 2.7 (don't know how Iforgot it).
3.3 is only open for security issues, so not backporting.
msg224055 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2014-07-26 13:12
Updating versions to reflect branch changes. Will come in handy for those tracking for manual packaging backports
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 64074
2014-07-26 13:12:02koobssetmessages: + msg224055
versions: + Python 2.7, Python 3.5, - Python 3.3
2014-07-26 12:46:33neologixsetmessages: + msg224052
2014-07-26 12:45:37python-devsetmessages: + msg224051
2014-07-26 12:27:47koobssetmessages: + msg224048
2014-07-25 17:54:33neologixsetstatus: open -> closed
resolution: fixed
messages: + msg223981

stage: resolved
2014-07-25 17:45:59python-devsetnosy: + python-dev
messages: + msg223980
2014-07-24 18:46:25neologixsetfiles: + find_unused_race.diff
keywords: + patch
messages: + msg223868
2014-07-24 08:28:48BreamoreBoysetnosy: + BreamoreBoy
messages: + msg223818
2013-12-04 15:25:12neirbowjsetnosy: + neirbowj
messages: + msg205227
2013-12-03 18:09:55neologixsetmessages: + msg205131
2013-12-03 10:17:39pitroucreate