Skip to content

Avoid TSan warnings in faulthandler #143108

@colesbury

Description

@colesbury

Bug report

The faulthandler module's code for printing stack traces is not thread-safe:

  • That's mostly okay -- faulthandler is mostly triggered when something goes wrong, like a segfault or a deadlock/timeout, so best effort is acceptable.
  • In free threaded Python, we don't print out stacktraces for all threads on a segfault, but we do print them on a timeout. That can lead to TSan reported data races on timeouts.

I think we want to keep the timeout behavior the same, which means living with some data races:

  • It mostly works and is useful.
  • There's no one "current thread" in a timeout. The "dump traceback later" thread (faulthandler_thread) doesn't have a thread state / hold the GIL, so it's a different situation than on segfault, where the crashing thread's stacktrace is the most useful (and safest to access).

We also have some suppressions in suppressions_free_threading.txt, but these are out of date.

I think we should add _Py_NO_SANITIZE_THREAD to the relevant faulthandler.c functions so that TSan doesn't report data races when faulthandler is running.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions