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

Segmentation fault in asyncio #82966

Closed
akayunov mannequin opened this issue Nov 13, 2019 · 8 comments
Closed

Segmentation fault in asyncio #82966

akayunov mannequin opened this issue Nov 13, 2019 · 8 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes topic-asyncio type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@akayunov
Copy link
Mannequin

akayunov mannequin commented Nov 13, 2019

BPO 38785
Nosy @vstinner, @asvetlov, @1st1, @miss-islington, @akayunov
PRs
  • bpo-38785: Prevent asyncio from crashing  #17144
  • [3.8] bpo-38785: Prevent asyncio from crashing (GH-17144) #17147
  • [3.7] bpo-38785: Prevent asyncio from crashing (GH-17144) #17148
  • Files
  • scratch_15.py
  • 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 2019-11-13.21:55:19.610>
    created_at = <Date 2019-11-13.08:34:09.900>
    labels = ['3.7', '3.8', '3.9', 'type-crash', 'expert-asyncio']
    title = 'Segmentation fault in asyncio'
    updated_at = <Date 2019-11-13.21:55:19.604>
    user = 'https://github.com/akayunov'

    bugs.python.org fields:

    activity = <Date 2019-11-13.21:55:19.604>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-11-13.21:55:19.610>
    closer = 'asvetlov'
    components = ['asyncio']
    creation = <Date 2019-11-13.08:34:09.900>
    creator = 'akayunov'
    dependencies = []
    files = ['48712']
    hgrepos = []
    issue_num = 38785
    keywords = ['patch']
    message_count = 8.0
    messages = ['356523', '356524', '356526', '356527', '356528', '356557', '356559', '356560']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'asvetlov', 'yselivanov', 'miss-islington', 'akayunov']
    pr_nums = ['17144', '17147', '17148']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue38785'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @akayunov
    Copy link
    Mannequin Author

    akayunov mannequin commented Nov 13, 2019

    Get Segmentation fault on run script in attachment.

    @akayunov akayunov mannequin added 3.7 (EOL) end of life topic-asyncio type-crash A hard crash of the interpreter, possibly with a core dump labels Nov 13, 2019
    @akayunov
    Copy link
    Mannequin Author

    akayunov mannequin commented Nov 13, 2019

    Get seg fault on running script in attachment:

    root@fake:/opt/securisync/be# python3.7 scratch_15.py
    In tratata before
    In tratata2 before
    Segmentation fault

    @asvetlov
    Copy link
    Contributor

    Thanks for the report!
    I would say that deriving from the future class without calling super().__init__() is an error.
    After fixing this the snippet raises expected "RuntimeError: yield was used instead of yield from in task" error.

    @vstinner
    Copy link
    Member

    The crash occurs in _asyncio_Future_get_loop():

    (gdb) frame
    #0 0x00007fffea2fe689 in _Py_INCREF (op=0x0) at ./Include/object.h:459
    459 op->ob_refcnt++;

    (gdb) up
    #1 0x00007fffea301b14 in _asyncio_Future_get_loop_impl (self=0x7fffea2615f0)
    at /home/vstinner/python/master/Modules/_asynciomodule.c:1094
    1094 Py_INCREF(self->fut_loop);

    (gdb) p self->fut_loop
    $1 = 0x0

    (gdb) where
    #0 0x00007fffea2fe689 in _Py_INCREF (op=0x0) at ./Include/object.h:459
    #1 0x00007fffea301b14 in _asyncio_Future_get_loop_impl (self=0x7fffea2615f0)
    at /home/vstinner/python/master/Modules/_asynciomodule.c:1094
    #2 0x00007fffea2fef01 in _asyncio_Future_get_loop (self=0x7fffea2615f0,
    _unused_ignored=0x0)
    at /home/vstinner/python/master/Modules/clinic/_asynciomodule.c.h:252
    #3 0x0000000000645364 in cfunction_vectorcall_NOARGS (
    func=<built-in method get_loop of Qwe2 object at remote 0x7fffea2615f0>,
    args=0x0, nargsf=0, kwnames=0x0) at Objects/methodobject.c:424
    #4 0x000000000042f8d1 in _PyObject_VectorcallTstate (tstate=0x81ae00,
    callable=<built-in method get_loop of Qwe2 object at remote 0x7fffea2615f0>, args=0x0, nargsf=0, kwnames=0x0) at ./Include/cpython/abstract.h:111
    #5 0x000000000042f930 in _PyObject_Vectorcall (
    callable=<built-in method get_loop of Qwe2 object at remote 0x7fffea2615f0>, args=0x0, nargsf=0, kwnames=0x0) at ./Include/cpython/abstract.h:120
    #6 0x000000000042f988 in _PyObject_CallNoArg (
    func=<built-in method get_loop of Qwe2 object at remote 0x7fffea2615f0>)
    at ./Include/cpython/abstract.h:148
    #7 0x000000000042fc57 in PyObject_CallNoArgs (
    func=<built-in method get_loop of Qwe2 object at remote 0x7fffea2615f0>)
    at Objects/call.c:83
    #8 0x00007fffea2ffc16 in get_future_loop (
    fut=<Qwe2(value=0) at remote 0x7fffea2615f0>)
    --Type <RET> for more, q to quit, c to continue without paging--q
    Quit

    (gdb) py-bt
    Traceback (most recent call first):
      <built-in method get_loop of Qwe2 object at remote 0x7fffea2615f0>
      <built-in method run of Context object at remote 0x7fffea215170>
      File "/home/vstinner/python/master/Lib/asyncio/events.py", line 81, in _run
        self._context.run(self._callback, *self._args)
      File "/home/vstinner/python/master/Lib/asyncio/base_events.py", line 2641, in _run_once
      File "/home/vstinner/python/master/Lib/asyncio/base_events.py", line 1101, in run_forever
        await waiter
      File "/home/vstinner/python/master/Lib/asyncio/base_events.py", line 621, in run_until_complete
        self.run_forever()
      File "/home/vstinner/python/master/Lib/asyncio/runners.py", line 299, in run
      File "/home/vstinner/python/master/scratch_15.py", line 56, in <module>
        asyncio.run(main())

    @asvetlov
    Copy link
    Contributor

    Looks like get_future_loop() function misses ENSURE_FUTURE_ALIVE macro call.

    @miss-islington
    Copy link
    Contributor

    New changeset dad6be5 by Miss Islington (bot) (Andrew Svetlov) in branch 'master':
    bpo-38785: Prevent asyncio from crashing (GH-17144)
    dad6be5

    @miss-islington
    Copy link
    Contributor

    New changeset 87b4d39 by Miss Islington (bot) in branch '3.7':
    bpo-38785: Prevent asyncio from crashing (GH-17144)
    87b4d39

    @miss-islington
    Copy link
    Contributor

    New changeset 694c03f by Miss Islington (bot) in branch '3.8':
    bpo-38785: Prevent asyncio from crashing (GH-17144)
    694c03f

    @asvetlov asvetlov added 3.8 only security fixes 3.9 only security fixes labels Nov 13, 2019
    @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.7 (EOL) end of life 3.8 only security fixes 3.9 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

    3 participants