-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-117657: Fix some races in tracebacks #121748
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Irit Katriel <[email protected]>
LGTM, but I'd suggest to have another reviewer with more knowledge of the thread safe patterns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the races in our tests involving tracebacks are broader than this.
The critical sections on getters and setters probably still makes sense, but I don't think they'll fix the traceback races.
The big problem is using sys._current_exceptions()
to access exceptions for other threads while they are running. That function runs in a stop-the-world context, but the exception tracebacks are created lazily when other threads are resumed. I think that will still not be thread-safe even with this change.
Objects/object.c
Outdated
@@ -2360,12 +2360,12 @@ new_reference(PyObject *op) | |||
#if !defined(Py_GIL_DISABLED) | |||
op->ob_refcnt = 1; | |||
#else | |||
op->ob_tid = _Py_ThreadId(); | |||
_Py_atomic_store_uintptr_release(&op->ob_tid, _Py_ThreadId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to do this, at least not for now. I want to wait until we fix all the other races before we address new_reference
because there are perf implications and the race is in practice benign.
The "release" memory order is also stronger (and more expensive on arm64) than necessary.
TSAN reported race:
and