Skip to content

Assertion failure in tstate_set_stack #143191

Closed

Description

@devdanzin

Crash report

What happened?

It's possible to make the interpreter abort by running the code below:

import _thread

for x in range(10):
    _thread.stack_size(59877)

    _thread.start_joinable_thread(str)

Backtrace:

python: Python/ceval.c:530: void tstate_set_stack(PyThreadState *, uintptr_t, uintptr_t): Assertion `(top - base) >= _PyOS_MIN_STACK_SIZE' failed.

Thread 2 "python" 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  0x000055555585e771 in tstate_set_stack (tstate=tstate@entry=0x555555dea4d0, base=base@entry=140737352556544, top=top@entry=140737352612288) at Python/ceval.c:530
#8  0x000055555585e665 in _Py_InitializeRecursionLimits (tstate=tstate@entry=0x555555dea4d0) at Python/ceval.c:574
#9  0x000055555595ff7b in _PyThreadState_Attach (tstate=0x555555dea4d0) at Python/pystate.c:2159
#10 0x0000555555a45088 in thread_run (boot_raw=boot_raw@entry=0x555555dcde50) at ./Modules/_threadmodule.c:384
#11 0x000055555598475f in pythread_wrapper (arg=0x555555dca850) at Python/thread_pthread.h:234
#12 0x00007ffff7ca3d64 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:448

Sometimes a different abort will happen, but I was never able to record it under GDB.

Message for abort 2:

python: Python/pystate.c:239: void bind_gilstate_tstate(PyThreadState *): Assertion `tstate_is_alive(tstate)' failed.
Aborted (core dumped)

Found using fusil by @vstinner.

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+ free-threading build (heads/main:cf6758ff9eb, Dec 26 2025, 14:20:15) [Clang 21.1.2 (2ubuntu6)]

Linked PRs

Activity

  1. colesbury commented on Dec 28, 2025

    @colesbury
    Contributor

    Not free threading specific -- crash happens in the default build too

  2. changed the title [-]Assertion failure in `tstate_set_stack` on a free threading build[/-] [+]Assertion failure in `tstate_set_stack`[/+] on Dec 28, 2025
  3. assigned and unassigned on Jan 1, 2026
  4. added 3 commits that reference this issue on Jan 9, 2026
  5. added a commit that references this issue on Jan 9, 2026
  6. added a commit that references this issue on Jan 9, 2026
  7. vstinner commented on Jan 9, 2026

    @vstinner
    Member

    Fixed in 3.14 and main branches. Thanks for your bug report.

  8. added a commit that references this issue on Jan 9, 2026
  9. added a commit that references this issue on Jan 12, 2026
  10. added a commit that references this issue on Feb 15, 2026
  11. added a commit that references this issue on Sep 14, 2026
  12. added a commit that references this issue on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-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