Skip to content

CPython should not assume that pthread_self returns the same value in fork parent and child #126688

Description

@nico

Summarized from SerenityOS/serenity#25263 by request of @colesbury:

It seems that at least Python 3.13 relies on pthread_self returning the same value in both the parent and the child process.
PyThread_get_thread_ident_ex

POSIX doesn't seem to mention if the value returned by pthread_self should be inherited by the child process.
pthread_self
fork

(It is the case on Linux, Hurd, FreeBSD, OpenBSD, Cygwin. It isn't on SerenityOS, and also not on Solaris 9/HP-UX 11 per https://bugs.python.org/issue7242.

It looks like the code add broke things is from this commit e21057b added in #118523 as part of #117657

Linked PRs

Activity

  1. self-assigned this
    on Nov 11, 2024
  2. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    on Nov 11, 2024
  3. added 4 commits that reference this issue on Nov 11, 2024
  4. added a commit that references this issue on Nov 12, 2024
  5. added a commit that references this issue on Nov 12, 2024
  6. oskar-skog commented on Nov 12, 2024

    @oskar-skog

    I think this can be closed now.

  7. ericsnowcurrently commented on Nov 21, 2024

    @ericsnowcurrently
    Member

    There may be other code that makes the same assumption about the thread ID. For example, in PyOS_AfterFork_Child():

    assert(tstate->thread_id == PyThread_get_thread_ident());
    #ifdef PY_HAVE_THREAD_NATIVE_ID
    tstate->native_thread_id = PyThread_get_thread_native_id();
    #endif

    This would break only on debug builds (or at least !defined(NDEBUG)).

    I'm guessing there are other places too.

  8. added a commit that references this issue on Dec 8, 2024
  9. added a commit that references this issue on Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.13only security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions