From c827d56fdf39e2f3556510a42639b77608fd3acf Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 23 Aug 2019 17:48:54 -0400 Subject: [PATCH 1/7] bpo-37933: do not segfault canceling never started faulthandler dump If there is no lock, do not try to release it. --- Lib/test/test_faulthandler.py | 3 +++ Modules/faulthandler.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 1cf20db1c7ff5c3..68e6c375a79de20 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -817,6 +817,9 @@ def test_disable_windows_exc_handler(self): self.assertEqual(output, []) self.assertEqual(exitcode, 0xC0000005) + def test_cancel_later_no_dump(self): + faulthandler.cancel_dump_traceback_later() + if __name__ == "__main__": unittest.main() diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 35e7b34c29ccd5d..011ab5fa28f2561 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -631,6 +631,11 @@ faulthandler_thread(void *unused) static void cancel_dump_traceback_later(void) { + /* If not scheduled, nothing to cancel */ + if (!thread.cancel_event) { + return; + } + /* Notify cancellation */ PyThread_release_lock(thread.cancel_event); From 2d3a7f1610253236d5143dd982e47c12d47e58a7 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 23 Aug 2019 18:24:10 -0400 Subject: [PATCH 2/7] TST: fix test to run in child process --- Lib/test/test_faulthandler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 68e6c375a79de20..5393303c0a64e4a 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -818,7 +818,13 @@ def test_disable_windows_exc_handler(self): self.assertEqual(exitcode, 0xC0000005) def test_cancel_later_no_dump(self): + code = dedent(""" + import faulthandler faulthandler.cancel_dump_traceback_later() + """) + output, exitcode = self.get_output(code) + self.assertEqual(output, []) + self.assertEqual(exitcode, 0x00000000) if __name__ == "__main__": From 1065411a3218c2f51e32e37e0689e6dc0db9cd05 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 26 Aug 2019 18:57:24 -0400 Subject: [PATCH 3/7] STY: fix style in tests --- Lib/test/test_faulthandler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 5393303c0a64e4a..be299cc2b981cae 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -819,12 +819,12 @@ def test_disable_windows_exc_handler(self): def test_cancel_later_no_dump(self): code = dedent(""" - import faulthandler - faulthandler.cancel_dump_traceback_later() + import faulthandler + faulthandler.cancel_dump_traceback_later() """) output, exitcode = self.get_output(code) self.assertEqual(output, []) - self.assertEqual(exitcode, 0x00000000) + self.assertEqual(exitcode, 0) if __name__ == "__main__": From 9d3f4e45971e0375676ba3194535c8c8c09c6329 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 27 Aug 2019 09:24:09 -0400 Subject: [PATCH 4/7] TST: add comment and better test name --- Lib/test/test_faulthandler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index be299cc2b981cae..bcf8509ec16690e 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -817,7 +817,9 @@ def test_disable_windows_exc_handler(self): self.assertEqual(output, []) self.assertEqual(exitcode, 0xC0000005) - def test_cancel_later_no_dump(self): + def test_cancel_later_without_dump_traceback_later(self): + # bpo-37933: Calling cancel_dump_traceback_later() + # without dump_traceback_later() must not gfaust code = dedent(""" import faulthandler faulthandler.cancel_dump_traceback_later() From ca02927e4fd0317c6433c3045c56e26b94b35a90 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 29 Aug 2019 10:27:32 -0400 Subject: [PATCH 5/7] Update Lib/test/test_faulthandler.py Co-Authored-By: Victor Stinner --- Lib/test/test_faulthandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index bcf8509ec16690e..3d5a96708d145fa 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -819,7 +819,7 @@ def test_disable_windows_exc_handler(self): def test_cancel_later_without_dump_traceback_later(self): # bpo-37933: Calling cancel_dump_traceback_later() - # without dump_traceback_later() must not gfaust + # without dump_traceback_later() must not segfaust code = dedent(""" import faulthandler faulthandler.cancel_dump_traceback_later() From 9b4cced25d30da24249ed5fac39cd20927e346e7 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 29 Aug 2019 10:28:29 -0400 Subject: [PATCH 6/7] DOC: fix typo (again) --- Lib/test/test_faulthandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 3d5a96708d145fa..b7000b058010d56 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -819,7 +819,7 @@ def test_disable_windows_exc_handler(self): def test_cancel_later_without_dump_traceback_later(self): # bpo-37933: Calling cancel_dump_traceback_later() - # without dump_traceback_later() must not segfaust + # without dump_traceback_later() must not segfault code = dedent(""" import faulthandler faulthandler.cancel_dump_traceback_later() From eaf7f35256ed377aa057dc249af6ac78845cee36 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 29 Aug 2019 11:16:15 -0400 Subject: [PATCH 7/7] Minimal commit to restart CI --- Lib/test/test_faulthandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index b7000b058010d56..b1aa8c32284ba39 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -819,7 +819,7 @@ def test_disable_windows_exc_handler(self): def test_cancel_later_without_dump_traceback_later(self): # bpo-37933: Calling cancel_dump_traceback_later() - # without dump_traceback_later() must not segfault + # without dump_traceback_later() must not segfault. code = dedent(""" import faulthandler faulthandler.cancel_dump_traceback_later()