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

IsolatedAsyncioTestCase freezes when exception is raised #83282

Closed
fornellas mannequin opened this issue Dec 19, 2019 · 5 comments
Closed

IsolatedAsyncioTestCase freezes when exception is raised #83282

fornellas mannequin opened this issue Dec 19, 2019 · 5 comments
Labels
3.8 only security fixes topic-asyncio type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@fornellas
Copy link
Mannequin

fornellas mannequin commented Dec 19, 2019

BPO 39101
Nosy @asvetlov, @1st1, @lisroach, @miss-islington, @fornellas, @r-owen
PRs
  • bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. #22654
  • [3.9] bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654) #22988
  • [3.8] bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654) #22989
  • 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 2020-10-26.16:29:40.338>
    created_at = <Date 2019-12-19.19:44:59.009>
    labels = ['3.8', 'type-crash', 'expert-asyncio']
    title = 'IsolatedAsyncioTestCase freezes when exception is raised'
    updated_at = <Date 2021-03-02.00:30:08.714>
    user = 'https://github.com/fornellas'

    bugs.python.org fields:

    activity = <Date 2021-03-02.00:30:08.714>
    actor = 'r3owen'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-10-26.16:29:40.338>
    closer = 'lisroach'
    components = ['asyncio']
    creation = <Date 2019-12-19.19:44:59.009>
    creator = 'fornellas'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39101
    keywords = ['patch']
    message_count = 5.0
    messages = ['358690', '379670', '383195', '383196', '387887']
    nosy_count = 6.0
    nosy_names = ['asvetlov', 'yselivanov', 'lisroach', 'miss-islington', 'fornellas', 'r3owen']
    pr_nums = ['22654', '22988', '22989']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue39101'
    versions = ['Python 3.8']

    @fornellas
    Copy link
    Mannequin Author

    fornellas mannequin commented Dec 19, 2019

    IsolatedAsyncioTestCase freezes whenever an exception that inherits from BaseException is raised:

    import unittest
    class TestHangsForever(unittest.IsolatedAsyncioTestCase):
        async def test_hangs_forever(self):
            raise BaseException("Hangs forever")
    if __name__ == "__main__":
        import unittest
        unittest.main()

    A kind of similar issue present on 3.7 was fixed on 3.8 here https://github.com/python/cpython/blob/3.8/Lib/asyncio/events.py#L84, where BaseExceptions would not be correctly handled by the event loop, this seems somewhat related.

    I had a look at IsolatedAsyncioTestCase implementation, did not spot any obvious broken thing there, I could use some light here. Thanks.

    @fornellas fornellas mannequin added 3.8 only security fixes topic-asyncio type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 19, 2019
    @lisroach
    Copy link
    Contributor

    New changeset 8374d2e by Lisa Roach in branch 'master':
    bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
    8374d2e

    @miss-islington
    Copy link
    Contributor

    New changeset 9d409d6 by Miss Islington (bot) in branch '3.9':
    bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
    9d409d6

    @miss-islington
    Copy link
    Contributor

    New changeset d549d0b by Miss Islington (bot) in branch '3.8':
    bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)
    d549d0b

    @r-owen
    Copy link
    Mannequin

    r-owen mannequin commented Mar 2, 2021

    Here is a variant that also hangs, I suspect for the same reason. The task raises asyncio.CancelledError which inherits from BaseException and my guess is it somehow kills the event loop.

    import asyncio
    import unittest
    
    
    class DemonstrateHang(unittest.IsolatedAsyncioTestCase):
        async def test_hang(self):
            task = asyncio.create_task(asyncio.sleep(2))
            await asyncio.sleep(0.1)
            task.cancel()
            await task
            # this also hangs: await asyncio.wait_for(task, 5)

    @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
    3.8 only security fixes topic-asyncio type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants