Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update crash handler behavior to opt-in #484

Merged
merged 11 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking of "AWS_CRT_MEMORY_TRACING", we have a hack so that it's always turned on when tests run. let's do the same thing and always turn on the crash handler

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