Skip to content
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

test_importlib test_multiprocessing_pool_circular_import() fails randomly on Thread sanitizer (free-threading) on GitHub Actions #125221

Closed
vstinner opened this issue Oct 9, 2024 · 2 comments
Labels
tests Tests in the Lib/test dir topic-free-threading

Comments

@vstinner
Copy link
Member

vstinner commented Oct 9, 2024

Example: https://github.com/python/cpython/actions/runs/11263361511/job/31321078076?pr=125219

 0:01:54 load avg: 4.86 [ 9/22/1] test_importlib failed (1 failure) (1 min 35 sec) -- running (2): test_io (1 min 20 sec), test_queue (1 min 3 sec)
test test_importlib failed -- Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython/Lib/test/test_importlib/test_threaded_import.py", line 255, in test_multiprocessing_pool_circular_import
    script_helper.assert_python_ok(fn)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
  File "/home/runner/work/cpython/cpython/Lib/test/support/script_helper.py", line 182, in assert_python_ok
    return _assert_python(True, *args, **env_vars)
  File "/home/runner/work/cpython/cpython/Lib/test/support/script_helper.py", line 167, in _assert_python
    res.fail(cmd_line)
    ~~~~~~~~^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Lib/test/support/script_helper.py", line 80, in fail
    raise AssertionError(f"Process return code is {exitcode}\n"
    ...<10 lines>...
                         f"---")
AssertionError: Process return code is 66
command line: ['/home/runner/work/cpython/cpython/python', '-X', 'faulthandler', '-I', '/home/runner/work/cpython/cpython/Lib/test/test_importlib/partial/pool_in_threads.py']

stdout:
---

---

stderr:
---

---

Linked PRs

@vstinner vstinner added tests Tests in the Lib/test dir topic-free-threading labels Oct 9, 2024
@vstinner vstinner changed the title test_importlib test_multiprocessing_pool_circular_import() fails on Thread sanitizer (free-threading) on GitHub Actions test_importlib test_multiprocessing_pool_circular_import() fails randomly on Thread sanitizer (free-threading) on GitHub Actions Oct 9, 2024
@colesbury
Copy link
Contributor

Looks like a data race on objreduce:

cpython/Objects/typeobject.c

Lines 7399 to 7409 in 0c5a48c

#define objreduce \
(_Py_INTERP_CACHED_OBJECT(_PyInterpreterState_GET(), objreduce))
PyObject *reduce, *res;
if (objreduce == NULL) {
PyObject *dict = lookup_tp_dict(&PyBaseObject_Type);
objreduce = PyDict_GetItemWithError(dict, &_Py_ID(__reduce__));
if (objreduce == NULL && PyErr_Occurred()) {
return NULL;
}
}

colesbury added a commit to colesbury/cpython that referenced this issue Oct 10, 2024
The lazy initialization of `objreduce` wasn't thread-safe in the free
threading build. Instead, initialize the interpreter's cached `objreduce`
field as part of the initialization of interpreter's types.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 11, 2024
…_` (pythonGH-125267)

(cherry picked from commit b12e992)

Co-authored-by: Sam Gross <colesbury@gmail.com>
kumaraditya303 pushed a commit that referenced this issue Oct 11, 2024
…__` (GH-125267) (#125305)

gh-125221: Fix free-threading data race in `object.__reduce_ex__` (GH-125267)
(cherry picked from commit b12e992)

Co-authored-by: Sam Gross <colesbury@gmail.com>
@vstinner
Copy link
Member Author

Thank you for the quick fix @colesbury!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir topic-free-threading
Projects
None yet
Development

No branches or pull requests

3 participants