Skip to content

Thread ID assertion in pystate.c failing under WASI #110455

Closed

Description

@brettcannon

Bug report

Bug description:

The following assert fails under a debug build with WASI:

assert(tstate->thread_id > 0);

It's probably due to the pthread stubs always returning 0 as the thread ID:

PyAPI_FUNC(pthread_t) pthread_self(void)
{
return 0;
}

It can probably be solved by making the assertion conditional on `HAVE_PTHREAD_STUBS not being defined:

#if !defined(HAVE_PTHREAD_STUBS)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.12only security fixes
    3.13only security fixes
    on Oct 6, 2023
  2. brettcannon commented on Oct 6, 2023

    @brettcannon
    MemberAuthor

    This fixes it:

    diff --git a/Python/pystate.c b/Python/pystate.c
    index dcc6c11221..f7042d0e21 100644
    --- a/Python/pystate.c
    +++ b/Python/pystate.c
    @@ -270,7 +270,9 @@ unbind_tstate(PyThreadState *tstate)
         // XXX assert(tstate_is_alive(tstate));
         assert(tstate_is_bound(tstate));
         // XXX assert(!tstate->_status.active);
    +#ifndef HAVE_PTHREAD_STUBS
         assert(tstate->thread_id > 0);
    +#endif
     #ifdef PY_HAVE_THREAD_NATIVE_ID
         assert(tstate->native_thread_id > 0);
     #endif
  3. self-assigned this
    on Oct 6, 2023
  4. added a commit that references this issue on Oct 6, 2023
  5. added a commit that references this issue on Oct 6, 2023
  6. added a commit that references this issue on Oct 6, 2023
  7. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13only security fixesOS-wasiinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions