Skip to content

Commit a9d3a25

Browse files
committed
pythongh-110031: Skip test_threading fork tests if ASAN (python#110100)
Skip test_threading tests using thread+fork if Python is built with Address Sanitizer (ASAN). (cherry picked from commit 86e76ab)
1 parent 69a9f47 commit a9d3a25

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

Lib/test/test_threading.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@
3535
platforms_to_skip = ('netbsd5', 'hp-ux11')
3636

3737

38+
# gh-89363: Skip fork() test if Python is built with Address Sanitizer (ASAN)
39+
# to work around a libasan race condition, dead lock in pthread_create().
40+
skip_if_asan_fork = support.skip_if_sanitizer(
41+
"libasan has a pthread_create() dead lock",
42+
address=True)
43+
44+
45+
def skip_unless_reliable_fork(test):
46+
if not support.has_fork_support:
47+
return unittest.skip("requires working os.fork()")(test)
48+
if sys.platform in platforms_to_skip:
49+
return unittest.skip("due to known OS bug related to thread+fork")(test)
50+
if support.check_sanitizer(address=True):
51+
return unittest.skip("libasan has a pthread_create() dead lock related to thread+fork")(test)
52+
return test
53+
54+
3855
def restore_default_excepthook(testcase):
3956
testcase.addCleanup(setattr, threading, 'excepthook', threading.excepthook)
4057
threading.excepthook = threading.__excepthook__
@@ -531,7 +548,7 @@ def test_daemon_param(self):
531548
t = threading.Thread(daemon=True)
532549
self.assertTrue(t.daemon)
533550

534-
@support.requires_fork()
551+
@skip_unless_reliable_fork
535552
def test_dummy_thread_after_fork(self):
536553
# Issue #14308: a dummy thread in the active list doesn't mess up
537554
# the after-fork mechanism.
@@ -563,7 +580,7 @@ def background_thread(evt):
563580
self.assertEqual(out, b'')
564581
self.assertEqual(err, b'')
565582

566-
@support.requires_fork()
583+
@skip_unless_reliable_fork
567584
def test_is_alive_after_fork(self):
568585
# Try hard to trigger #18418: is_alive() could sometimes be True on
569586
# threads that vanished after a fork.
@@ -599,7 +616,7 @@ def f():
599616
th.start()
600617
th.join()
601618

602-
@support.requires_fork()
619+
@skip_unless_reliable_fork
603620
@unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
604621
def test_main_thread_after_fork(self):
605622
code = """if 1:
@@ -620,8 +637,7 @@ def test_main_thread_after_fork(self):
620637
self.assertEqual(err, b"")
621638
self.assertEqual(data, "MainThread\nTrue\nTrue\n")
622639

623-
@unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
624-
@support.requires_fork()
640+
@skip_unless_reliable_fork
625641
@unittest.skipUnless(hasattr(os, 'waitpid'), "test needs os.waitpid()")
626642
def test_main_thread_after_fork_from_nonmain_thread(self):
627643
code = """if 1:
@@ -1068,8 +1084,7 @@ def test_1_join_on_shutdown(self):
10681084
"""
10691085
self._run_and_join(script)
10701086

1071-
@support.requires_fork()
1072-
@unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
1087+
@skip_unless_reliable_fork
10731088
def test_2_join_in_forked_process(self):
10741089
# Like the test above, but from a forked interpreter
10751090
script = """if 1:
@@ -1089,8 +1104,7 @@ def test_2_join_in_forked_process(self):
10891104
"""
10901105
self._run_and_join(script)
10911106

1092-
@support.requires_fork()
1093-
@unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
1107+
@skip_unless_reliable_fork
10941108
def test_3_join_in_forked_from_thread(self):
10951109
# Like the test above, but fork() was called from a worker thread
10961110
# In the forked process, the main Thread object must be marked as stopped.
@@ -1160,8 +1174,7 @@ def main():
11601174
rc, out, err = assert_python_ok('-c', script)
11611175
self.assertFalse(err)
11621176

1163-
@support.requires_fork()
1164-
@unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug")
1177+
@skip_unless_reliable_fork
11651178
def test_reinit_tls_after_fork(self):
11661179
# Issue #13817: fork() would deadlock in a multithreaded program with
11671180
# the ad-hoc TLS implementation.
@@ -1187,7 +1200,7 @@ def do_fork_and_wait():
11871200
for t in threads:
11881201
t.join()
11891202

1190-
@support.requires_fork()
1203+
@skip_unless_reliable_fork
11911204
def test_clear_threads_states_after_fork(self):
11921205
# Issue #17094: check that threads states are cleared after fork()
11931206

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Skip test_threading tests using thread+fork if Python is built with Address
2+
Sanitizer (ASAN). Patch by Victor Stinner.

0 commit comments

Comments
 (0)