-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-116738: Make grp module thread-safe #135434
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
base: main
Are you sure you want to change the base?
Conversation
Note: I am not sure if there is a CI setup where |
#elif defined(Py_GIL_DISABLED) | ||
static PyMutex getgrgid_mutex = {0}; | ||
PyMutex_Lock(&getgrgid_mutex); | ||
// The getgrgid() function need not be thread-safe. | ||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/getgrgid.html | ||
p = getgrgid(gid); | ||
if (p == NULL) { | ||
// Unlock the mutex on error. The following error handling block will | ||
// handle the rest. | ||
PyMutex_Unlock(&getgrgid_mutex); | ||
} |
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 we should use the lock in the default build as well. The thread safety issues here apply to multiple interpreters as well and this lock would address that.
@@ -248,6 +261,17 @@ grp_getgrnam_impl(PyObject *module, PyObject *name) | |||
} | |||
|
|||
Py_END_ALLOW_THREADS | |||
#elif defined(Py_GIL_DISABLED) |
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.
Same here.
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 269b454 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135434%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
Make
grp
module methodsgetgrgid()
andgetgrnam()
thread-safe when the GIL is disabled andgetgrgid_r()
/getgrnam_r()
C APIs are not available.Lib/test/test_free_threading/test_ft.py
to reuserun_concurrently()
across multiple tests.cc: @mpage @colesbury @Yhg1s