Skip to content

JIT: Assertion failure in stopiteration_error #143183

@devdanzin

Description

@devdanzin

Crash report

What happened?

It's possible to abort a JIT build by running the code below:

def f1():
    class AsyncIter:
        def __init__(self):
            self.limit = 0
            self.count = 0

        def __aiter__(self):
            return self

        async def __anext__(self):
            if self.count >= self.limit:
                ...
            self.count += 1j

    class AsyncCtx:
        async def async_for_driver():
            try:
                for _ in range(5000):
                    try:
                        async for _ in AsyncIter():
                            ...
                    except TypeError:
                        ...
            except Exception:
                ...

        c = async_for_driver()
        while True:
            try:
                c.send(None)
            except StopIteration:
                break


for i in range(30):
    f1()

Backtrace:

python: Python/intrinsics.c:145: PyObject *stopiteration_error(PyThreadState *, PyObject *): Assertion `PyExceptionInstance_Check(exc)' failed.

Program received signal SIGABRT, Aborted.

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=6, no_tid=0) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (threadid=<optimized out>, signo=6) at ./nptl/pthread_kill.c:89
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:100
#3  0x00007ffff7c45e2e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff7c28888 in __GI_abort () at ./stdlib/abort.c:77
#5  0x00007ffff7c287f0 in __assert_fail_base (fmt=<optimized out>, assertion=<optimized out>, file=<optimized out>, line=<optimized out>, function=<optimized out>) at ./assert/assert.c:118
#6  0x00007ffff7c3c19f in __assert_fail (assertion=<optimized out>, file=<optimized out>, line=<optimized out>, function=<optimized out>) at ./assert/assert.c:127
#7  0x0000555555fe5142 in stopiteration_error (tstate=0x555556e6afb0 <_PyRuntime+359376>, exc=0x555556beeaa0 <_Py_TrueStruct>) at Python/intrinsics.c:145
#8  0x0000555555e76230 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/generated_cases.c.h:2589
#9  0x0000555555b4168b in _PyEval_EvalFrame (tstate=0x555556e6afb0 <_PyRuntime+359376>, frame=0x7d0ffd203528, throwflag=0) at ./Include/internal/pycore_ceval.h:119
#10 gen_send_ex2 (gen=0x7d0ffd2034e0, arg=0x555556c0b4a0 <_Py_NoneStruct>, presult=0x7bfff5bad660, exc=0) at Objects/genobject.c:239
#11 0x0000555555b420f5 in gen_send (op=0x7d0ffd2034e0, arg=0x555556c0b4a0 <_Py_NoneStruct>) at Objects/genobject.c:365
#12 0x0000555555ea7bc7 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/generated_cases.c.h:3661
#13 0x0000555555e6db18 in _PyEval_EvalFrame (tstate=0x555556e6afb0 <_PyRuntime+359376>, frame=0x7e8ff6fe5310, throwflag=0) at ./Include/internal/pycore_ceval.h:119
#14 _PyEval_Vector (tstate=<optimized out>, func=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=0x0) at Python/ceval.c:2542
#15 0x0000555555e5be84 in builtin___build_class__ (self=<optimized out>, args=<optimized out>, nargs=2, kwnames=<optimized out>) at Python/bltinmodule.c:205
#16 0x0000555555e6ffcf in _Py_BuiltinCallFastWithKeywords_StackRefSteal (callable=..., arguments=<optimized out>, total_args=2) at Python/ceval.c:1181
#17 0x0000555555e8ff48 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/generated_cases.c.h:2287
#18 0x0000555555e6db18 in _PyEval_EvalFrame (tstate=0x555556e6afb0 <_PyRuntime+359376>, frame=0x7e8ff6fe5220, throwflag=0) at ./Include/internal/pycore_ceval.h:119
#19 _PyEval_Vector (tstate=<optimized out>, func=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>, kwnames=0x0) at Python/ceval.c:2542
#20 0x0000555555e6d535 in PyEval_EvalCode (co=<optimized out>, globals=<optimized out>, locals=0x7c7ff7086540) at Python/ceval.c:1008

Output from running with PYTHON_LLTRACE=4 PYTHON_OPT_DEBUG=4:
2492_abort_lltrace_opt_debug.txt

Found using lafleur.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.15.0a3+ (heads/main-dirty:cc48bf0fde8, Dec 24 2025, 22:16:25) [Clang 21.1.2 (2ubuntu6)]

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions