Skip to content

Commit 7984dc2

Browse files
[3.11] gh-110656: Fix logging test_post_fork_child_no_deadlock() if ASAN (GH-110657) (#110665)
gh-110656: Fix logging test_post_fork_child_no_deadlock() if ASAN (GH-110657) Skip test_post_fork_child_no_deadlock() if Python is built with ASAN. Add support.HAVE_ASAN_FORK_BUG. (cherry picked from commit f901f56) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 46347d3 commit 7984dc2

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
msvcrt = None
7878

7979

80-
if support.check_sanitizer(address=True):
80+
if support.HAVE_ASAN_FORK_BUG:
8181
# gh-89363: Skip multiprocessing tests if Python is built with ASAN to
8282
# work around a libasan race condition: dead lock in pthread_create().
83-
raise unittest.SkipTest("libasan has a pthread_create() dead lock")
83+
raise unittest.SkipTest("libasan has a pthread_create() dead lock related to thread+fork")
8484

8585

8686
def latin(s):

Lib/test/support/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ def skip_if_sanitizer(reason=None, *, address=False, memory=False, ub=False):
426426
skip = check_sanitizer(address=address, memory=memory, ub=ub)
427427
return unittest.skipIf(skip, reason)
428428

429+
# gh-89363: True if fork() can hang if Python is built with Address Sanitizer
430+
# (ASAN): libasan race condition, dead lock in pthread_create().
431+
HAVE_ASAN_FORK_BUG = check_sanitizer(address=True)
432+
429433

430434
def system_must_validate_cert(f):
431435
"""Skip the test on TLS certificate validation failures."""

Lib/test/test_logging.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@
7676
pass
7777

7878

79+
# gh-89363: Skip fork() test if Python is built with Address Sanitizer (ASAN)
80+
# to work around a libasan race condition, dead lock in pthread_create().
81+
skip_if_asan_fork = unittest.skipIf(
82+
support.HAVE_ASAN_FORK_BUG,
83+
"libasan has a pthread_create() dead lock related to thread+fork")
84+
85+
7986
class BaseTest(unittest.TestCase):
8087

8188
"""Base class for logging tests."""
@@ -682,6 +689,7 @@ def remove_loop(fname, tries):
682689
# register_at_fork mechanism is also present and used.
683690
@support.requires_fork()
684691
@threading_helper.requires_working_threading()
692+
@skip_if_asan_fork
685693
def test_post_fork_child_no_deadlock(self):
686694
"""Ensure child logging locks are not held; bpo-6721 & bpo-36533."""
687695
class _OurHandler(logging.Handler):

Lib/test/test_threading.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,12 @@
3737
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
3838

3939

40-
# gh-89363: Skip fork() test if Python is built with Address Sanitizer (ASAN)
41-
# to work around a libasan race condition, dead lock in pthread_create().
42-
skip_if_asan_fork = support.skip_if_sanitizer(
43-
"libasan has a pthread_create() dead lock",
44-
address=True)
45-
46-
4740
def skip_unless_reliable_fork(test):
4841
if not support.has_fork_support:
4942
return unittest.skip("requires working os.fork()")(test)
5043
if sys.platform in platforms_to_skip:
5144
return unittest.skip("due to known OS bug related to thread+fork")(test)
52-
if support.check_sanitizer(address=True):
45+
if support.HAVE_ASAN_FORK_BUG:
5346
return unittest.skip("libasan has a pthread_create() dead lock related to thread+fork")(test)
5447
return test
5548

0 commit comments

Comments
 (0)