From f7451c0f3be15a607de97ebba3c5efb893c9bb50 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 5 Jul 2023 19:42:49 -0500 Subject: [PATCH] Update crash handler behavior to opt-in (#484) --- README.md | 3 +++ source/module.c | 9 ++++++++- test/__init__.py | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dde3ff70..1d64c50f1 100644 --- a/README.md +++ b/README.md @@ -66,3 +66,6 @@ Please note that on Mac, once a private key is used with a certificate, that cer ``` static: certificate has an existing certificate-key pair that was previously imported into the Keychain. Using key from Keychain instead of the one provided. ``` + +## Crash Handler +You can enable the crash handler by setting the environment variable `AWS_CRT_CRASH_HANDLER=1`. This will print the callstack to `stderr` in the event of a fatal error. diff --git a/source/module.c b/source/module.c index f120daaa7..a971bb6d0 100644 --- a/source/module.c +++ b/source/module.c @@ -804,6 +804,7 @@ static PyMethodDef s_module_methods[] = { static const char s_module_name[] = "_awscrt"; PyDoc_STRVAR(s_module_doc, "C extension for binding AWS implementations of MQTT, HTTP, and friends"); +AWS_STATIC_STRING_FROM_LITERAL(s_crash_handler_env_var, "AWS_CRT_CRASH_HANDLER"); /******************************************************************************* * Module Init @@ -828,11 +829,17 @@ PyMODINIT_FUNC PyInit__awscrt(void) { } s_init_allocator(); - s_install_crash_handler(); /* Don't report this memory when dumping possible leaks. */ struct aws_allocator *nontracing_allocator = aws_default_allocator(); + struct aws_string *crash_handler_env = NULL; + aws_get_environment_value(nontracing_allocator, s_crash_handler_env_var, &crash_handler_env); + if (aws_string_eq_c_str(crash_handler_env, "1")) { + s_install_crash_handler(); + } + aws_string_destroy(crash_handler_env); + aws_http_library_init(nontracing_allocator); aws_auth_library_init(nontracing_allocator); aws_mqtt_library_init(nontracing_allocator); diff --git a/test/__init__.py b/test/__init__.py index 6d319e80f..4b2d44e28 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -6,6 +6,7 @@ # the "noqa" comment prevents the autoformatter from moving this line below other imports import os os.environ['AWS_CRT_MEMORY_TRACING'] = '2' # noqa +os.environ['AWS_CRT_CRASH_HANDLER'] = '1' # noqa from awscrt import NativeResource from awscrt._test import check_for_leaks