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: Segfault when passing invalid argument to asyncio.ensure_future
Type: crash Stage: resolved
Components: asyncio Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Jason McKellar, asvetlov, yselivanov
Priority: normal Keywords:

Created on 2018-06-06 01:17 by Jason McKellar, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg318794 - (view) Author: Jason McKellar (Jason McKellar) Date: 2018-06-06 01:17
If time.monotonic() is yielded from a generator that is passed to asyncio.ensure_future a segfault occurs when it's scheduled. 

The example below shows time.monotonic called in the generator, however the segfault will also occur if a function is called (not a lambda) that uses time.monotonic.

I've tested on Python 3.6 and 3.7.0b4.


For example:

import asyncio
import time
import faulthandler

faulthandler.enable()

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

# Note that ensure_future argument is generator
# which yields time.monotonic() return value
tasks = [asyncio.ensure_future(
    time.monotonic()
    for i in range(1)
)]
results_future = asyncio.gather(*tasks)

# Segmentation fault
results = loop.run_until_complete(results_future)


The fault handler output:

Fatal Python error: Segmentation fault

Current thread 0x00007f4b7a042b88 (most recent call first):
  File "/usr/local/lib/python3.7/asyncio/events.py", line 88 in _run
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 1738 in _run_once
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 521 in run_forever
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 553 in run_until_complete
  File "/test-seg.py", line 19 in <module>
Segmentation fault (core dumped)


An example with time.monotonic call nested in a function:

import asyncio
import time
import faulthandler

def bad():
    return {'nested': time.monotonic()}

faulthandler.enable()

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

tasks = [asyncio.ensure_future(
    bad()
    for i in range(1)
)]
results_future = asyncio.gather(*tasks)

# Segmentation fault
results = loop.run_until_complete(results_future)
msg318798 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-06-06 02:59
Thanks for reporting it.  Looks like this has been fixed in 3.6 (not yet released) and 3.7.0b5 in issue 33584.
History
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 77957
2018-06-06 02:59:13yselivanovsetstatus: open -> closed
resolution: out of date
messages: + msg318798

stage: resolved
2018-06-06 01:17:44Jason McKellarcreate