[New-bugs-announce] [issue33776] Segfault when passing invalid argument to asyncio.ensure_future

Jason McKellar report at bugs.python.org
Tue Jun 5 21:17:44 EDT 2018


New submission from Jason McKellar <jason at deadtreepages.com>:

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)

----------
components: asyncio
messages: 318794
nosy: Jason McKellar, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Segfault when passing invalid argument to asyncio.ensure_future
type: crash
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33776>
_______________________________________


More information about the New-bugs-announce mailing list