Commit Graph

37 Commits

Author SHA1 Message Date
Miss Islington (bot) 8e96d85386
[3.13] gh-117657: Avoid race in `PAUSE_ADAPTIVE_COUNTER` in free-threaded build (GH-122190) (#122475)
The adaptive counter doesn't do anything currently in the free-threaded
build and TSan reports a data race due to concurrent modifications to
the counter.
(cherry picked from commit 2b163aa9e7)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-30 18:18:25 +00:00
Miss Islington (bot) 9d5dde5006
[3.13] gh-122201: Lock mutex when setting handling_thread to NULL (GH-122204) (#122319)
In the free-threaded build, we need to lock pending->mutex when clearing
the handling_thread in order not to race with a concurrent
make_pending_calls in the same interpreter.
(cherry picked from commit c557ae97d6)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-26 17:30:08 +00:00
Miss Islington (bot) 85e9018a01
[3.13] gh-117657: Remove TSAN suppressions for _abc.c (GH-121508) (#121598)
The functions look thread-safe and I haven't seen any warnings issued
when running the tests locally.
(cherry picked from commit 7641743d48)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-10 21:34:14 +00:00
Miss Islington (bot) 927f882d76
[3.13] gh-117657: Fix TSan race in _PyDict_CheckConsistency (GH-121551) (#121590)
The only remaining race in dictobject.c was in _PyDict_CheckConsistency
when the dictionary has shared keys.
(cherry picked from commit 3ec719fabf)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-10 18:28:44 +00:00
Miss Islington (bot) f0d16f7e82
[3.13] gh-117657: Fix TSAN races in setobject.c (GH-121511) (#121541)
The `used` field must be written using atomic stores because `set_len`
and iterators may access the field concurrently without holding the
per-object lock.
(cherry picked from commit 9c08f40a61)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-07-09 16:36:36 +00:00
Miss Islington (bot) 06fd745dd9
[3.13] gh-117657: Fix data races reported by TSAN in some set methods (GH-120914) (#121240)
Refactor the fast Unicode hash check into `_PyObject_HashFast` and use relaxed
atomic loads in the free-threaded build.

After this change, the TSAN doesn't report data races for this method.
(cherry picked from commit 294e724964)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-07-01 19:40:28 +00:00
Miss Islington (bot) 396f8b0b98
[3.13] gh-117657: Fix `__slots__` thread safety in free-threaded build (GH-119368) (#120655)
Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`.
These functions implement `__slots__` accesses for Python objects.
(cherry picked from commit 362cd2680b)

Co-authored-by: Daniele Parmeggiani <8658291+dpdani@users.noreply.github.com>
2024-06-17 19:12:25 +00:00
Miss Islington (bot) 0dbb86c5be
[3.13] gh-117657: Fix TSan reported data race on ioctl_works (GH-120175) (#120654)
(cherry picked from commit 460cc9e14e)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-17 17:52:49 +00:00
Miss Islington (bot) 6e3e112428
[3.13] gh-117657: Add TSAN suppression for set_default_allocator_unlocked (GH-120500) (#120510)
gh-117657: Add TSAN suppression for set_default_allocator_unlocked (GH-120500)

Add TSAN suppression for set_default_allocator_unlocked
(cherry picked from commit 2bacc2343c)

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-06-14 16:34:07 +00:00
Miss Islington (bot) 3067c62a34
[3.13] gh-117657: Make PyType_HasFeature atomic (GH-120210) (#120443)
gh-117657: Make PyType_HasFeature atomic (GH-120210)

Make PyType_HasFeature atomic
(cherry picked from commit eebae2c460)

Co-authored-by: Ken Jin <kenjin@python.org>
2024-06-13 18:06:04 +08:00
Miss Islington (bot) 91c4444d22
[3.13] gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165) (GH-120403)
gh-117657: Make Py_TYPE and Py_SET_TYPE thread safe (GH-120165)
(cherry picked from commit e16aed63f6)

Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Nadeshiko Manju <me@manjusaka.me>
2024-06-12 21:37:26 +08:00
Miss Islington (bot) 517733ce3c
[3.13] gh-117657: Fix TSAN race involving import lock (GH-118523) (#120169)
This adds a `_PyRecursiveMutex` type based on `PyMutex` and uses that
for the import lock. This fixes some data races in the free-threaded
build and generally simplifies the import lock code.
(cherry picked from commit e21057b999)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-06 18:03:01 +00:00
Miss Islington (bot) ee7d2681f6
[3.13] gh-117657: Fix race involving GC and heap initialization (GH-119923) (#120038)
The `_PyThreadState_Bind()` function is called before the first
`PyEval_AcquireThread()` so it's not synchronized with the stop the
world GC. We had a race where `gc_visit_heaps()` might visit a thread's
heap while it's being initialized.

Use a simple atomic int to avoid visiting heaps for threads that are not
yet fully initialized (i.e., before `tstate_mimalloc_bind()` is called).

The race was reproducible by running:
`python Lib/test/test_importlib/partial/pool_in_threads.py`.
(cherry picked from commit e69d068ad0)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-04 14:08:10 +00:00
Sam Gross 79fae3b0a1
[3.13] gh-117657: Fix itertools.count thread safety (GH-119268) (#120007)
Fix itertools.count in free-threading mode
(cherry picked from commit 87939bd579)

Co-authored-by: Arnon Yaari <wiggin15@yahoo.com>
2024-06-03 22:47:34 +00:00
Sam Gross ae705319fc
[3.13] gh-117657: Fix race involving immortalizing objects (GH-119927) (#120005)
The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.

(cherry picked from commit 47fb4327b5)
2024-06-03 22:21:32 +00:00
Miss Islington (bot) ca37034baa
[3.13] gh-117657: Avoid `sem_clockwait` in TSAN (GH-119915) (#119992)
The `sem_clockwait` function is not currently instrumented, which leads
to false positives.
(cherry picked from commit 41c1cefbae)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-03 18:07:22 +00:00
Miss Islington (bot) e5dfcea3e3
[3.13] gh-117657: Fix data races report by TSAN unicode-hash (gh-119907) (gh-119963)
gh-117657: Fix data races report by TSAN unicode-hash (gh-119907)
(cherry picked from commit 0594a27e5f)

Co-authored-by: Donghee Na <donghee.na@python.org>
2024-06-03 03:45:44 +00:00
Miss Islington (bot) 9d3de7b0ed
[3.13] gh-117657: Fix TSAN reported race in `_PyEval_IsGILEnabled`. (GH-119921) (#119939)
The GIL may be disabled concurrently with this call so we need to use a
relaxed atomic load.
(cherry picked from commit f3b89a63cb)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-02 14:42:46 +00:00
Miss Islington (bot) 9f9be95d66
[3.13] gh-117657: Add TSAN suppression for `set_discard_entry` (GH-119908) (#119914)
Seen in CI occasionally when running `test_weakref`.
(cherry picked from commit 7dc745d1f5)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-01 16:42:16 +00:00
Miss Islington (bot) 48054d2306
[3.13] gh-117657: Fix TSAN race in QSBR assertion (GH-119887) (#119904)
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be
atomic to avoid reported races.
(cherry picked from commit 90ec19fd33)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-01 14:51:55 +00:00
Miss Islington (bot) 48f3378d6c
[3.13] gh-117657: Fix TSAN race in free-threaded GC (GH-119883) (#119903)
Only call `gc_restore_tid()` from stop-the-world contexts.
`worklist_pop()` can be called while other threads are running, so use a
relaxed atomic to modify `ob_tid`.
(cherry picked from commit 60593b2052)

Co-authored-by: Sam Gross <colesbury@gmail.com>
2024-06-01 14:26:12 +00:00
Miss Islington (bot) 7dc9e923d1
[3.13] gh-117657: Log TSAN warnings to separate files and archive them (GH-118747) (#118931)
This ensures we don't lose races that occur in subprocesses or
interleave races from workers running in parallel.

Log files are collected and packaged into a zipfile that can be
downloaded from the "Artifacts" section of the workflow run.
(cherry picked from commit b88889e9ff)

Co-authored-by: mpage <mpage@meta.com>
2024-05-10 22:27:17 +00:00
Miss Islington (bot) 0becae366c
[3.13] gh-117657: Fix QSBR race condition (GH-118843) (#118905)
`_Py_qsbr_unregister` is called when the PyThreadState is already
detached, so the access to `tstate->qsbr` isn't safe without locking the
shared mutex. Grab the `struct _qsbr_shared` from the interpreter
instead.
(cherry picked from commit 33d20199af)

Co-authored-by: Alex Turner <alexturner@meta.com>
2024-05-10 15:13:17 +00:00
Miss Islington (bot) 4480dd86d9
[3.13] gh-117657: Fix data races reported by TSAN on `interp->threads.main` (GH-118865) (#118904)
Use relaxed loads/stores when reading/writing to this field.
(cherry picked from commit 22d5185308)

Co-authored-by: mpage <mpage@meta.com>
2024-05-10 14:40:06 +00:00
Miss Islington (bot) 982c73a33e
[3.13] gh-117657: Replace TSAN suppresions with more specific rules (GH-118722) (#118870)
Using `race:` filters out warnings if the function appears anywhere in
the stack trace. This can hide a lot of unrelated warnings, especially
for a function like `_PyEval_EvalFrameDefault`, which is somewhere on
the stack more often than not.

Change all free-threaded suppressions to `race_top:`, which only matches
the top frame, and add any new suppressions this exposes.
(cherry picked from commit 98ff3f65c0)

Co-authored-by: Brett Simmers <swtaarrs@users.noreply.github.com>
2024-05-09 21:36:25 +00:00
Miss Islington (bot) 7b9ca26812
[3.13] gh-117657: Fix data races when writing / reading `ob_gc_bits` (GH-118292) (#118796)
Use relaxed atomics when reading / writing to the field. There are still a
few places in the GC where we do not use atomics. Those should be safe as
the world is stopped.
(cherry picked from commit cb6f75a32c)

Co-authored-by: mpage <mpage@meta.com>
2024-05-08 21:31:37 +00:00
mpage 37d0950022
gh-117657: Disable the function/code cache in free-threaded builds (#118301)
This is only used by the specializing interpreter and the tier 2
optimizer, both of which are disabled in free-threaded builds.
2024-05-03 16:21:04 -04:00
Alex Turner 2ba1aed596
gh-117657: TSAN fix race on `gstate->young.count` (#118313) 2024-04-29 20:26:26 +00:00
mpage a5eeb832c2
gh-117657: Fix race data race in `_Py_IsOwnedByCurrentThread()` (#118258) 2024-04-26 10:39:08 -04:00
Dino Viehland 5da0280648
gh-117657: Fixes a few small TSAN issues in dictobject (#118200)
Fixup TSAN errors for dict
2024-04-25 08:53:29 -07:00
mpage cce5ae6082
gh-117657: Add a couple more TSAN suppressions (#118256) 2024-04-25 11:48:16 -04:00
mpage f14e9f9154
gh-117657: Fix data race in `_Py_IsImmortal` (#118261)
The load of `ob_ref_local races with stores. Using a relaxed load is
sufficient; stores to the field are relaxed.
2024-04-25 11:31:57 -04:00
Dino Viehland 1e4a4c4897
gh-117657: use relaxed loads for checking dict keys immortality (#118067)
Use relaxed load to check if dictkeys are immortal
2024-04-19 09:25:08 -07:00
mpage 0d29302155
gh-117657: Quiet erroneous TSAN reports of data races in `_PySeqLock` (#117955)
Quiet erroneous TSAN reports of data races in `_PySeqLock`

TSAN reports a couple of data races between the compare/exchange in
`_PySeqLock_LockWrite` and the non-atomic loads in `_PySeqLock_{Abandon,Unlock}Write`.
This is another instance of TSAN incorrectly modeling failed compare/exchange
as a write instead of a load.
2024-04-17 17:19:28 +00:00
mpage b6c62c79e7
gh-117657: Fix data races in the method cache in free-threaded builds (#117954)
Fix data races in the method cache in free-threaded builds

These are technically data races, but I think they're benign (to
the extent that that is actually possible). We update cache entries
non-atomically but read them atomically from another thread, and there's
nothing that establishes a happens-before relationship between the
reads and writes that I can see.
2024-04-17 09:42:56 -07:00
mpage 47832067da
gh-117657: Add TSAN suppressions for the free-threaded build (#117736)
Additionally, reduce the iterations for a few weakref tests that would
otherwise take a prohibitively long amount of time (> 1 hour) when TSAN
is enabled and the GIL is disabled.
2024-04-15 12:08:25 -04:00
Donghee Na ebf29b3a02
gh-112536: Add --tsan test for reasonable TSAN execution times. (gh-116601) 2024-03-16 01:07:16 +09:00