Author martius
Recipients martius, yselivanov
Date 2016-11-23.18:03:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479924207.48.0.511908736136.issue28782@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

I stumbled upon a SEGFAULT while trying Python 3.6.0 on a project using
asyncio. I can't really figure out what's happening, so I reduced the original
code triggering the bug down to a reproducible case (which looks a bit clunky,
sorry). The case has been tested on two Linux systems (Archlinux and Debian),
and with several versions of Python.

The bug appears between 3.6.0a4 (most recent version tested not affected) and
3.60b1 (so before the C asyncio module I believe), and is not fixed in the
current repository tip (changeset: 105345:3addf93f4111).

I also produced a traceback using gdb (see bellow).

The segfault happens around the "await" in the body of Cursor._read_data(),
interestingly, if I change anything in the body of the method, the SEGFAULT
disappears and the code works as expected. Also, it seems that calling it from
an other coroutine (main() in the example) is required to trigger the bug.

Cheers,
Martin


Case (also attached as test.py) : 
import asyncio

loop = asyncio.get_event_loop()


class Connection:
    def read_until(self, *args, **kwargs):
        return self

    async def all(self):
        return b"\n"


class Cursor:
    def __init__(self):
        self._connection = Connection()
        self._max_bytes = 100
        self._data = bytearray()

    async def _read_data(self):
        # XXX segfault there, if I change anything in the code, it works...
        while True:
            data = await self._connection.read_until(
                b'\n', max_bytes=self._max_bytes).all()
            self._max_bytes -= len(data)
            if data == b'\n':
                break
            self._data.extend(data)


async def main():
    await Cursor()._read_data()


loop.run_until_complete(main())


Traceback extract (with Python3.6.0b4, --with-pydebug on Linux):

Program received signal SIGSEGV, Segmentation fault.
0x000000000046d177 in _PyGen_yf (gen=gen@entry=0x7ffff34bdaf8) at Objects/genobject.c:361
361	        Py_INCREF(yf);
(gdb) bt
#0  0x000000000046d177 in _PyGen_yf (gen=gen@entry=0x7ffff34bdaf8) at Objects/genobject.c:361
#1  0x000000000052f49c in _PyEval_EvalFrameDefault (f=0x7ffff67067d8, throwflag=<optimized out>)
    at Python/ceval.c:1992
#2  0x000000000052a0fc in PyEval_EvalFrameEx (f=f@entry=0x7ffff67067d8, throwflag=throwflag@entry=0)
    at Python/ceval.c:718
#3  0x000000000046d393 in gen_send_ex (gen=gen@entry=0x7ffff34bdc08, arg=<optimized out>, 
    exc=exc@entry=0, closing=closing@entry=0) at Objects/genobject.c:189
#4  0x000000000046de8d in _PyGen_Send (gen=gen@entry=0x7ffff34bdc08, arg=<optimized out>)
    at Objects/genobject.c:308
#5  0x00007ffff384ba2c in task_step_impl (task=task@entry=0x7ffff3263bd8, exc=exc@entry=0x0)
    at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:1963
#6  0x00007ffff384c72e in task_step (task=0x7ffff3263bd8, exc=0x0)
    at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:2247
#7  0x00007ffff384ca79 in task_call_step (arg=<optimized out>, task=<optimized out>)
    at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:1848
#8  TaskSendMethWrapper_call (o=<optimized out>, args=<optimized out>, kwds=<optimized out>)
    at (...)/Python-3.6.0b4/Modules/_asynciomodule.c:1167
#9  0x0000000000446702 in PyObject_Call (func=0x7ffff37d7f60, args=0x7ffff7fb8058, kwargs=0x0)
    at Objects/abstract.c:2246
#10 0x00000000005295c8 in do_call_core (func=func@entry=0x7ffff37d7f60, 
    callargs=callargs@entry=0x7ffff7fb8058, kwdict=kwdict@entry=0x0) at Python/ceval.c:5054
#11 0x0000000000534c64 in _PyEval_EvalFrameDefault (f=0xb4cb48, throwflag=<optimized out>)
    at Python/ceval.c:3354
#12 0x000000000052a0fc in PyEval_EvalFrameEx (f=f@entry=0xb4cb48, throwflag=throwflag@entry=0)
    at Python/ceval.c:718
#13 0x000000000052a1cc in _PyFunction_FastCall (co=<optimized out>, args=0xb4c5b0, nargs=nargs@entry=1, 
    globals=<optimized out>) at Python/ceval.c:4867
(...)
History
Date User Action Args
2016-11-23 18:03:27martiussetrecipients: + martius, yselivanov
2016-11-23 18:03:27martiussetmessageid: <1479924207.48.0.511908736136.issue28782@psf.upfronthosting.co.za>
2016-11-23 18:03:27martiuslinkissue28782 messages
2016-11-23 18:03:26martiuscreate