Skip to content

Commit

Permalink
Update crash handler behavior to opt-in (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Jul 6, 2023
1 parent 4625964 commit f7451c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 8 additions & 1 deletion source/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f7451c0

Please sign in to comment.