GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PyThreadState_Clear, tstate_activate/_PyThreadState_Attach and drop_gil race race on TSAN · Issue #121751 · python/cpython

PyThreadState_Clear, tstate_activate/_PyThreadState_Attach and drop_gil race race on TSAN #121751

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
PyThreadState_Clear, tstate_activate/_PyThreadState_Attach and drop_gil race race on TSAN#121751
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@Fidget-Spinner
Fidget-Spinner
opened on Jul 14, 2024
Issue body actions

Bug report

Bug description:

Reproducer:
Remove all suppressions from https://github.com/python/cpython/blob/main/Tools/tsan/suppressions_free_threading.txt

Build and Run with TSAN #117657

We get races like

SUMMARY: ThreadSanitizer: data race /home/ken/Documents/GitHub/cpython/Python/pystate.c:1665:32 in PyThreadState_Clear
==================
ThreadSanitizer: reported 1 warnings
==================
WARNING: ThreadSanitizer: data race (pid=40494)
  Read of size 4 at 0x72a400014030 by main thread:
    #0 PyThreadState_Clear /home/ken/Documents/GitHub/cpython/Python/pystate.c:1661:5 (python+0x5d9458) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #1 _PyThreadState_DeleteList /home/ken/Documents/GitHub/cpython/Python/pystate.c:1917:9 (python+0x5da7f4) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #2 _Py_Finalize /home/ken/Documents/GitHub/cpython/Python/pylifecycle.c:2038:5 (python+0x59d929) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #3 Py_Exit /home/ken/Documents/GitHub/cpython/Python/pylifecycle.c:3391:9 (python+0x5a0e35) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #4 handle_system_exit /home/ken/Documents/GitHub/cpython/Python/pythonrun.c:604:9 (python+0x5e0bf9) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #5 _PyErr_PrintEx /home/ken/Documents/GitHub/cpython/Python/pythonrun.c:613:5 (python+0x5e0bf9)
    #6 PyErr_PrintEx /home/ken/Documents/GitHub/cpython/Python/pythonrun.c:690:5 (python+0x5e00aa) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #7 PyErr_Print /home/ken/Documents/GitHub/cpython/Python/pythonrun.c:696:5 (python+0x5e00aa)
    #8 _PyRun_SimpleStringFlagsWithName /home/ken/Documents/GitHub/cpython/Python/pythonrun.c:521:9 (python+0x5e00aa)
    #9 pymain_run_command /home/ken/Documents/GitHub/cpython/Modules/main.c:252:11 (python+0x6208ad) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #10 pymain_run_python /home/ken/Documents/GitHub/cpython/Modules/main.c:631:21 (python+0x6208ad)
    #11 Py_RunMain /home/ken/Documents/GitHub/cpython/Modules/main.c:719:5 (python+0x6208ad)
    #12 pymain_main /home/ken/Documents/GitHub/cpython/Modules/main.c:749:12 (python+0x620f43) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #13 Py_BytesMain /home/ken/Documents/GitHub/cpython/Modules/main.c:773:12 (python+0x620fe6) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #14 main /home/ken/Documents/GitHub/cpython/./Programs/python.c:15:12 (python+0x15b850) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)

  Previous write of size 4 at 0x72a400014030 by thread T3:
    #0 tstate_activate /home/ken/Documents/GitHub/cpython/Python/pystate.c:2004:28 (python+0x5dadbd) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #1 _PyThreadState_Attach /home/ken/Documents/GitHub/cpython/Python/pystate.c:2081:9 (python+0x5dadbd)
    #2 _Py_HandlePending /home/ken/Documents/GitHub/cpython/Python/ceval_gil.c:1234:9 (python+0x554778) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #3 _PyEval_EvalFrameDefault /home/ken/Documents/GitHub/cpython/Python/generated_cases.c.h:907:13 (python+0x4bb5f3) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)
    #4 _PyEval_EvalFrame /home/ken/Documents/GitHub/cpython/./Include/internal/pycore_ceval.h:119:16 (python+0x297c3b) (BuildId: e8ff96bc7d1e595a25cb4534a571573eaa53d4f4)

Considering it's writing to a bit struct, the race seems plausible.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Activity

  1. Fidget-Spinner
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    topic-free-threading
    on Jul 14, 2024
  2. colesbury commented on Jul 14, 2024

    @colesbury
    colesbury
    on Jul 14, 2024
    Contributor
    More actions

    This is the same underlying issue as #110052 -- daemon threads (or regular threads if you press ctrl-c) may still be running during _Py_Finalize, but their PyThreadState structs get freed out from underneath them. The underlying bug affects both the default and free-threaded build.

    See also my comment on that issue: #110052 (comment)

    The fix is a bit tricky, so I think we should probably prioritize the other remaining data races first.

  3. kumaraditya303 commented on Apr 19, 2025

    @kumaraditya303
    kumaraditya303
    on Apr 19, 2025
    Contributor
    More actions

    I think this is fixed now with #130649

  4. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Apr 19, 2025
  5. kumaraditya303
    closed this as not plannedon May 9, 2025
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.