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

test_asyncio unstable in refleak mode #66302

Closed
pitrou opened this issue Jul 30, 2014 · 8 comments
Closed

test_asyncio unstable in refleak mode #66302

pitrou opened this issue Jul 30, 2014 · 8 comments
Labels
tests Tests in the Lib/test dir topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Jul 30, 2014

BPO 22104
Nosy @gvanrossum, @pitrou, @vstinner, @giampaolo, @zware, @1st1
Files
  • issue22104.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-08-04.16:19:11.168>
    created_at = <Date 2014-07-30.00:31:21.073>
    labels = ['type-bug', 'tests', 'expert-asyncio']
    title = 'test_asyncio unstable in refleak mode'
    updated_at = <Date 2014-08-04.16:19:11.166>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2014-08-04.16:19:11.166>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-08-04.16:19:11.168>
    closer = 'python-dev'
    components = ['Tests', 'asyncio']
    creation = <Date 2014-07-30.00:31:21.073>
    creator = 'pitrou'
    dependencies = []
    files = ['36166']
    hgrepos = []
    issue_num = 22104
    keywords = ['patch']
    message_count = 8.0
    messages = ['224280', '224284', '224287', '224288', '224293', '224305', '224311', '224741']
    nosy_count = 7.0
    nosy_names = ['gvanrossum', 'pitrou', 'vstinner', 'giampaolo.rodola', 'python-dev', 'zach.ware', 'yselivanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22104'
    versions = ['Python 3.4', 'Python 3.5']

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 30, 2014

    test_asyncio doesn't give usable results when looking for refleaks:

    $ ./python -m test -R 2:4 test_asyncio
    [1/1] test_asyncio
    beginning 6 repetitions
    123456
    ......
    test_asyncio leaked [212, -106, 265, -6360] references, sum=-5989
    test_asyncio leaked [59, -29, 76, -1799] memory blocks, sum=-1693
    1 test failed:
        test_asyncio

    @pitrou pitrou added tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Jul 30, 2014
    @gvanrossum
    Copy link
    Member

    Was this always so or did it recently start? Victor has made a ton of changes.

    Anyway, I imagine there may be some objects stuck in cycles and the collection may not happen until a random later time, and the tests do timing-specific stuff so the number of objects created and deleted varies per run.

    Perhaps adding some well-aimed gc.collect() calls to some tearDown() methods would make this go away?

    @zware
    Copy link
    Member

    zware commented Jul 30, 2014

    I think I'm to blame for exposing this in 4f9f7e0fe1fd. I have a theory on why that exposed it; I think regrtest is holding an extra reference to the TestSuite in runtest_inner since it is using a different branch now that test_asyncio doesn't have a test_main function.

    @vstinner
    Copy link
    Member

    It may be related to the issue bpo-17911.

    @vstinner
    Copy link
    Member

    It may be related to the issue bpo-17911.

    I checked: it is. The strange reference count can be seen with a single test. Example:

    $ ./python -m test -R 3:3: -m test_default_exc_handler_coro test_asyncio 
    [1/1] test_asyncio
    beginning 6 repetitions
    123456
    ......
    test_asyncio leaked [53, 53, -106] references, sum=0
    test_asyncio leaked [15, 15, -30] memory blocks, sum=0
    1 test failed:
        test_asyncio

    This test uses a coroutine which raises an exception. The exception is stored in a Task object. But the exception contains also a traceback which indirectly creates a reference cycle. For example, the zero_error_coro() coroutine of the test uses the free variable "self".

    It's very difficult to find all objects of a reference cycle. We can try to break some cycles, it's already done Task._step() which sets self to None, but it's a waste of time. IMO the correct fix is to not store frame objects in an exception: see the issue bpo-17911.

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 30, 2014

    Le 30/07/2014 06:08, STINNER Victor a écrit :

    This test uses a coroutine which raises an exception. The exception
    is
    stored in a Task object. But the exception contains also a traceback
    which indirectly creates a reference cycle.

    regrtest calls gc.collect().

    @zware
    Copy link
    Member

    zware commented Jul 30, 2014

    I checked on my theory, and removing the extra reference to 'tests' from the runtest_inner scope fixes it for me:

    $ python -m test -R 3:3: test_asyncio
    Running Debug|Win32 interpreter...
    [1/1] test_asyncio
    beginning 6 repetitions
    123456
    ......
    1 test OK.

    Here's the patch.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 4, 2014

    New changeset 9bca86812857 by Zachary Ware in branch '3.4':
    Issue bpo-22104: Don't hold a reference to the loaded TestSuite in runtest_inner
    http://hg.python.org/cpython/rev/9bca86812857

    New changeset 7bc53cf8b2df by Zachary Ware in branch 'default':
    Closes bpo-22104: Merge with 3.4
    http://hg.python.org/cpython/rev/7bc53cf8b2df

    @python-dev python-dev mannequin closed this as completed Aug 4, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants